Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Get only whose rows that contains max Date

$
0
0

Hi All,

I have query that looks something like this :

select 1 as Id, '2014-05-25' as ToDate union select 1 as Id, '2014-05-26' as ToDate union select 2 as Id, '2014-05-25' as ToDate union select 2 as Id, '2014-05-27' as ToDate union select 3 as Id, '2014-05-20' as ToDate union select 3 as Id, '2014-05-19' as ToDate And i need result looks like this: (get only whose rows that contains max ToDate per Id)

Id |ToDate

------------ 1 2014-05-26 2 2014-05-27 3 2014-05-20

Is there a way to do this in the most efficient ?

Regards, Evgeniy.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>