SQL语句 查询最新记录

要求:SQL语句按ID以最新时间查询最新的一条记录

 

方法1:

select * from (select *, ROW_NUMBER() over(partition by id order by updateDate desc) as num from table) b 

where num=1 order by id

 

方法2:

select* from table where updateDate in(select max(updateDate) from table group by id)

 

参考:


http://www.cnblogs.com/lhws/archive/2012/03/20/2407522.html

posted on 2016-07-04 15:37  zhucheng88  阅读(662)  评论(0编辑  收藏  举报

导航

Document