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

Group By SQL question

Status
Not open for further replies.

medwards

Programmer
Nov 9, 2001
8
0
0
US
As I've discovered, when using Group By and Max() you are not allowed to select columns if those columns do not appear in either the Group By clause or the Max() function. Is there another way to do this? I need the ID number of the records where the Max occurs. For example, this is not allowed:

SELECT RecordID, SSN, MAX(SomeDate) AS MaxDate
FROM TableA
GROUP BY SSN

but this is:

SELECT SSN, MAX(SomeDate) AS MaxDate
FROM TableA
GROUP BY SSN

So how do I get the ID number of the rows that have the max date for each SSN?

Thanks
 
Perhaps this belongs in the SQL Server: Programming or the MS Access forums?
 
yes it does. accidentally posted it to the wrong forum... sorry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top