Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Selecting by Max Date

Author  Topic 

aspark
Starting Member

1 Post

Posted - 2015-03-22 : 18:59:03
Hello,

I am first selecting by a type value in col 'Type'.
In the resulting records each Type (each has an unique ID number) has up to three values with varying dates.
I need to select all records by unique ID number with the most recent date.
Can anyone help?

Thanks.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2015-03-23 : 01:41:15

select t1.* from table as t1 inner join
(
select id, max(datecolumn) as datecolumn from table
group by id
) as t2 on t1.id=t2.id and t1.datecolumn=t2.datecolumn

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -