Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to retrieve the most recent value of each ID

783568Aug 11 2010 — edited Aug 15 2010
Hello
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 12 2010
Added on Aug 11 2010
6 comments
1,418 views