tags:

views:

140

answers:

1

I have a table with columns

ID, DateStamp

and the ID need not be unique.

How do I write a query that will give me a list of IDs with the minimum DateStamp and the maximum DateStamp?

So, for example, for a given ID, the output may look like:

938423, 1/1/2000, 12/13/2003

[I am running SQL Server 2000.]

+17  A: 

The following should do it:

SELECT ID, MIN(DateStamp), MAX(DateStamp)
FROM TableName
GROUP BY ID

EDIT Added from clause for clarity, be sure to change TableName to the actual table name

Noah Goodrich
Thank's Mitchel.
Noah Goodrich
@Jake, don't forget to marked this as accepted answer as well.
Jonas Lincoln
Erm, I would, but there is no such button. :/
Jake
@Jake, It's not a button its the big CHECK mark that you should see immediately under the number of votes for the answer. ;-)
Noah Goodrich