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.]

1 Answer 1

17

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

Sign up to request clarification or add additional context in comments.

2 Comments

Erm, I would, but there is no such button. :/
@Jake, It's not a button its the big CHECK mark that you should see immediately under the number of votes for the answer. ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.