I would like to create a single query that would retrieve the maximum value of a grouped rowset.
We have a table with the following information:
ID
Description
Time
We can have data such as the following:
ID Desc Time
-- ---- ----
9 asdasd 2006-11-08 12:40:57.000
9 asdasdfs 2006-11-08 13:18:29.000
9 w3ewe 2006-11-08 13:19:04.000
9 werwer 2006-11-08 13:20:15.000
10 sdfsdf 2006-11-12 15:49:27.000
10 aassdasd 2006-11-12 15:50:08.000
10 asdasd 2006-11-12 15:52:17.000
What I would like to get are the two rows for IDs 9 and 10 that contain the most recent time value (in the above case, it would be the first and fifth rows).
I have tried various options using group by but none seem to work. The key thing is that this needs to be handled in one query, without multiple steps requiring a stored procedure or a cursor.
Can this be done efficiently using one query and if so, does anyone have any ideas?
TIA.
We have a table with the following information:
ID
Description
Time
We can have data such as the following:
ID Desc Time
-- ---- ----
9 asdasd 2006-11-08 12:40:57.000
9 asdasdfs 2006-11-08 13:18:29.000
9 w3ewe 2006-11-08 13:19:04.000
9 werwer 2006-11-08 13:20:15.000
10 sdfsdf 2006-11-12 15:49:27.000
10 aassdasd 2006-11-12 15:50:08.000
10 asdasd 2006-11-12 15:52:17.000
What I would like to get are the two rows for IDs 9 and 10 that contain the most recent time value (in the above case, it would be the first and fifth rows).
I have tried various options using group by but none seem to work. The key thing is that this needs to be handled in one query, without multiple steps requiring a stored procedure or a cursor.
Can this be done efficiently using one query and if so, does anyone have any ideas?
TIA.