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 2005 Forums
 Transact-SQL (2005)
 How to get recent rows

Author  Topic 

SCHEMA
Posting Yak Master

192 Posts

Posted - 2009-05-19 : 13:14:17
I have table

id compno date
1 2 5/5/09
1 2 5/5/09
1 2 5/5/09
1 3 3/5/09
1 3 3/5/09


How do i get?

id compno date
1 2 5/5/09
1 2 5/5/09
1 2 5/5/09

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-19 : 13:23:31
[code]SELECT t.*
FROM table t
JOIN (SELECT id,max(date) as latest
FROM table
GROUP BY id) t1
on t.id=t1.id
and t.date=t1.latest
[/code]
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-05-20 : 05:51:30
select * from @temp where date = ( select max(Date) from @temp)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-20 : 06:25:43
Both will gie the difference result. Only OP should tell us which is needed

Madhivanan

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

- Advertisement -