查询重复的最新记录

[img]http://dl.iteye.com/upload/attachment/216624/211574f1-4810-3786-8132-bcca9f4c44a7.png[/img]

create table tt
(
id int identity(1,1) primary key,
name varchar(50) ,
date datetime ,
)



insert into tt(name,date) values('a','2001')
insert into tt(name,date) values('b','2002')
insert into tt(name,date) values('c','2003')
insert into tt(name,date) values('a','2004')
insert into tt(name,date) values('c','2009')
insert into tt(name,date) values('b','2008')
insert into tt(name,date) values('a','2007')
insert into tt(name,date) values('c','2005')


select * from tt a where id=(select  top 1 id from tt where name=a.name order by date desc)

你可能感兴趣的:(Java,C,C++,C#,SQL)