How to retrieve the most recent value of each ID
783568Aug 11 2010 — edited Aug 15 2010Hello
I have a history table that has these fields: ID, TimeStamp, Value. Every time that an ID is changed the application saves a record with its current value in the table which is (naturally) sorted by TimeStamp, for example:
ID TimeStamp Value
1 10:00 1
2 10:00 2
3 10:30 3
3 10:30 1
2 11:30 3
2 12:00 2
Now, I need to make a query that will give me (with best performance) only the latest record of each ID,
The result using the above example will be:
ID TimeStamp Value
1 10:00 1
2 12:00 2
3 10:30 1
How do I do that?