Home Forums SQL Server 2012 SQL Server 2012 - T-SQL Finding the most recent value for many record in a detail table (optimizing) RE: Finding the most recent value for many record in a detail table (optimizing)

  • Paul White (5/24/2013)


    This is a variation of the 'Top N per Group' problem, and there are many ways to express it in T-SQL. Whichever you choose, be sure to make the ORDER BY clause deterministic and provide a useful index...

    Thank you for the correction! yes, on the query in my system that looks into history is deterministic, my AdventureWorks example wasn't as well thought out as it could be 🙂

    More importantly giving a good example of what the right index should get you in a query plan