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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL question about unique fields plus other data

Status
Not open for further replies.

FlyBoy311

Programmer
Apr 18, 2007
1
US
I have an SQL question.. hopefully I can find some help here :)

Supposed this is my table..

ID OWNER CREATION_DATE
1 bob 1/1/2001
2 bob 2/2/2002
3 tom 3/3/2003
4 tom 4/4/2004

What I need to do is find the earliest entry based on date for each owner in the table. Obviously owners are not unique. I need a select statement that will return the OWNER and the CREATION_DATE corresponding to the earliest entry of that owner in the database.

Any ideas?
Thanks!
 
SELECT a.Owner, a.Creation_Date
FROM YourTable a WHERE Creation_Date =
(SELECT MIN(Creation_Date) FROM YourTable b WHERE a.Owner = b.Owner)
 
-OR-

SELECT a.Owner, MIN(a.Creation_Date) AS Creation_Date
FROM YourTable a
GROUP BY a.Owner
 
select statement that will return the OWNER and the CREATION_DATE corresponding to the earliest entry of that owner
You wanted simply this ?
SELECT OWNER, MIN(CREATION_DATE) EarliestDate
FROM yourTable
GROUP BY OWNER

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top