jfmckenzie
asked on
How to: Select Last Record for Each Record ID
My current query retrieves the following data
<Current Resultset>
id LastContactDate
1 10-jan-06
1 11-jan-06
1 12-jan-06
2 10-feb-06
2 11-feb-06
2 12-feb-06
I need to be able to select only the latest date for each record id.
<Required Resultset>
id LastDateContact
1 12-jan-06
2 12-feb-06
Thanks in advance
<Current Resultset>
id LastContactDate
1 10-jan-06
1 11-jan-06
1 12-jan-06
2 10-feb-06
2 11-feb-06
2 12-feb-06
I need to be able to select only the latest date for each record id.
<Required Resultset>
id LastDateContact
1 12-jan-06
2 12-feb-06
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys. Both comments correct, not sure how to allocate points so just accepted first answer.
>>not sure how to allocate points <<
See here from the EE Help:
More than one Expert helped solve my problem. What do I do?
https://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi69
See here from the EE Help:
More than one Expert helped solve my problem. What do I do?
https://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi69
SELECT ID, MAX(LastContactDate)LastCo
FRoM urTable
GROUP BY ID
Aneesh R!