SQL query - retreiving most recent record for an entity *resolved*
Say I've got the following table
---------------
|1|2006-10-04|
|1|2006-10-05|
|2|2006-10-04|
|2|2006-10-05|
---------------
How could I write a SQL query to return the most recent record for each id? The result should look like this
---------------
|1|2006-10-05|
|2|2006-10-05|
---------------
Re: SQL query - retreiving most recent record for an entity
Maybe something like this:
Code:
"Select * From TableName Where ID IN (Select ID From TableName Where Date = '" & Select MAX(DateField) From TableName Where ID = (Select Distinct(ID) From TableName) & "')"
Re: SQL query - retreiving most recent record for an entity
I ended up using
Code:
SELECT submitter_id,max(created_date)
FROM dbo.claim_stub WITH (NOLOCK)
GROUP BY submitter_id
Thanks for your response.
Re: SQL query - retreiving most recent record for an entity *resolved*
You dont need the '" & or & "' around the inner Select.
Here's an alternative method:
Code:
Select ID, Max([Date])
From TableName
GROUP BY ID
edit: oops, I arrived too late!