Click here to Skip to main content
16,016,157 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i have a table and 3 coloumn
CSS
ID  Name    Date
1   name1   2011-02-15 00:00:00.000
2   name2   2011-02-15 00:00:00.000
3   name2   2011-02-15 00:00:00.000
4   name1   2011-02-15 00:00:00.000
5   name1   2011-02-15 00:00:00.000
6   name2   2011-02-15 00:00:00.000

now i wanna find 2 last of same name and diffrent date of them
how can i do it?
Posted

1 solution

SQL
select top 2 t.Name, t.Date from
(
  select row_number() over(partiton by name, date order by name, date desc) as rowno, Name, Date
  from MyTableNameHere
) as t
where t.rowno=1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900