Question : how do i get the latest records per a specific criteria in a table?

I am using SQL Server 2008.

I have a table with the below data

ProductID    SalesDate           Status

20               1/21/2009             SalesPending
20               1/23/2009             SalesCompleted
21               1/22/2010             SalesInitiated
21               1/24/2010             SalesPending



Expected Results. Each productID, Status based on latest date

ProductID    SalesDate             Status

20               1/23/2009             SalesCompleted
21               1/24/2010             SalesPending

Answer : how do i get the latest records per a specific criteria in a table?

this would 1 example:
1:
2:
3:
select t.*
 from yourtable t
 where t.SalesDate = ( select max(i.SalesDate) from yourtable i where i.productid = t.productid )
Random Solutions  
 
programming4us programming4us