Reputation: 991
I am using sql server 2008, i have the following data
sNames sDate
(varchar(MAX)) (date)
========== =============
ALS 10/02/2012
SSP 11/03/2012
MRP 11/05/2012
ALS 14/06/2012
ALS 04/10/2012
ALS 03/11/2012
MRP 05/09/2012
PPL 18/08/2012
I want to order the list by sDate in desc but must show distinct sNames. kindly guide me
Upvotes: 0
Views: 93
Reputation: 8871
select max(sDate),sname from yourTable
group by sname
order by max(sDate) desc
Upvotes: 0
Reputation: 2895
Try below:
Select distinct snames
from yourtable
order by sdate desc
Upvotes: 0
Reputation: 204746
Using the latest dates for duplicate sNames
you can do
select sNames, max(sDate)
from your_table
group by sNames
order by max(sDate) desc
Upvotes: 5