I have inherited a table with a structure something like this:
ID Name Timestamp Data
----------------------------
1 A 40 ...
2 A 30 ...
3 A 20 ...
4 B 40 ...
5 B 20 ...
6 C 30 ...
7 C 20 ...
8 C 10 ...
ID
is an identity field and the primary key and there are non-unique indexes on the Name
and Timestamp
fields.
What is the most efficient way to get the most recent record for each item name, i.e. in the table above rows 1,4 and 6 should be returned as they are the most up-to-date entries for items A,B and C respectively.