Groups | Blog | Home
all groups > sql server (alternate) > may 2004 >

sql server (alternate) : Maximum Date in a group of records


David Portas
5/7/2004 9:51:17 AM
This query returns row(s) with the latest Enddate for each ID but the row
for ID='B' isn't the one you highlighted.

SELECT id, startdate, enddate
FROM SomeTable AS S
WHERE enddate =
(SELECT MAX(enddate)
FROM SomeTable
WHERE id = S.id)

Hope this helps.

--
David Portas
SQL Server MVP
--

Rashid
5/7/2004 11:59:52 AM
hi all,
i got is table:
Id StartDate EndDate
a 19/03/2001 18/03/2002
a 19/03/2002 18/04/2002*
b 13/08/2000 12/08/2001
b 13/08/2001 12/08/2002
b 13/08/2002 10/07/2002*

Sort command and groupins i am ok but i need to select only the records that
has the latest enddate. (See *)
any ideas? thanks in advance
rashid

AddThis Social Bookmark Button