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

subquery? max? 1

Status
Not open for further replies.

Pampers

Technical User
Apr 7, 2004
1,300
0
0
AN
Hi everyone,
Looking for a query that select the following:

id date number
1 12-11-2011 3
2 12-11-2011 5

from this dataset:

id date number
1 11-11-2011 2
1 12-11-2011 3
2 11-11-2011 4
2 12-11-2011 5
...

Can't figure it out
Regards Peter.

Pampers [afro]
Keeping it simple can be complicated
 
how about

select id,date,number
from tablename
where date=#12-11-2011#
 
Not enough information to give a good answer.

Are you looking for the maximum date for each id?
And the number that goes with it?
Is there a primary key?

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
You wanted this ?
Code:
SELECT A.id, A.date, A.number
FROM yourTable A INNER JOIN (
SELECT id, MAX([date]) AS LastDate FROM yourTable GROUP BY id
) L ON A.id = L.id AND A.date = L.LastaDate

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yep great PHV,
that was what I was looking for.

Also thanks to the others for their input.

Pampers [afro]
Keeping it simple can be complicated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top