仅选择最新版本的字段

Nic*_*rca 0 sql t-sql sql-server

我有一个ID模式,标题,日期的表模式

和数据看起来像这样:

1  The title1    2011-04-05 00:00:00.000
2  Another title 2011-04-11 00:00:00.000
3  The title1    2011-04-11 16:49:23.633
4  The title1    2011-04-11 00:00:00.000   
Run Code Online (Sandbox Code Playgroud)

我需要帮助sql给我每个标题的最新日期.所以上面数据的输出是

2  Another title 2011-04-11 00:00:00.000
3  The title1    2011-04-11 16:49:23.633
Run Code Online (Sandbox Code Playgroud)

ash*_*jay 5

select id,title,date from [schema]
where title in (select title from [schema] group by title having date=max(date))
Run Code Online (Sandbox Code Playgroud)

试试这个