Question : T-SQL for last date

i have table

ID      Product            Purc_Date            Customer            rate
01      Manggo            1/1/2009            John                  .01
02      Peach            1/3/2009            John                  .024
03      Apple            1/3/2009            Marry                  .2
04      Lemon            2/13/2009            Dave                  .4
05      Grape            2/15/2009            John                  .3
06      Peach            2/15/2009            Dave                  .1

I want to get last purchased date on each customer.

I want my returned querry will be like this :


ID      Product            Purc_Date            Customer            rate
03      Apple            1/3/2009            Marry                  .2
05      Grape            2/15/2009            John                  .3
06      Peach            2/15/2009            Dave                  .1

can anybody help me out?

Answer : T-SQL for last date


In my point of view, matthewspatrick solution is correct. if a customer has more thane one record with the maximum date, all those records have to be displayed.
Unless there is rewuirement that pick the max or min id record if more than one record present for the max date.
The asker can try like this also. Choose row_number or dense_rank depending on your requirement and the column names in order by clause.
1:
2:
3:
select * 
  from (select *,dense_rank() over ( partition by Customer order by Date desc) as RN from #tst ) as t1
 where t1.RN = 1
Open in New Window Select All
Random Solutions  
 
programming4us programming4us