Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving maximum row of a grouped rowset

Status
Not open for further replies.

D1000

Technical User
Aug 16, 2002
46
US
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.
 
I'm sorry, I should say it would be the first and last rows of the example I provided.
 
Strike that - should be the fourth and last rows.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top