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

Multiple Select Max Statements 2

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
Hi,

I want to select the lastest date from a table. But since alot of records have the same date, I end up with multiple records and I simply want to get one record. So I want to select the max date and also the max ID (which is the primary key)

Current Query
Code:
SELECT A.*
FROM PROFILES AS A
WHERE A.ACTIVE = 1 AND A.PROFILE_TYPE = 'TEST'
AND A.DATE = (SELECT Max(B.DATE) FROM PROFILES AS B WHERE B.ACTIVE = 1 AND B.PROFILE_TYPE = 'TEST')

Thank you for the help of PHV on my last post.
 
I can only guess that you have a primary key field ID in the table. Try this:
Code:
SELECT A.*
FROM PROFILES As A
WHERE A.Active = 1 AND A.PROFILE_TYPE = 'TEST'
AND A.ID = 
(SELECT TOP 1 ID
 FROM PROFILES B
 WHERE B.ACTIVE = 1 AND B.PROFILE_TYPE='TEST'
 ORDER BY [DATE] DESC, ID DESC)

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top