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.
| Author |
Topic |
|
outspaced
Starting Member
21 Posts |
Posted - 2006-12-07 : 11:46:53
|
| Hi,I have several records with the same ID, and I'd like to select the record where the id matches my id with the latest date.egname animal_id dateboris 2 01/02/03cedric 2 01/01/01mustapha 2 01/03/02gunther 4 10/05/05... I'd like to select the record for boris.Thanks,Alex |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-12-07 : 11:53:35
|
| [code]Select *from tbl t1where id = @idand [date] = (Select max([Date]) from tbl t2 where t1.id = t2.id)[/code]Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2006-12-07 : 12:21:00
|
| An alternative that may give a better plan ...select *from tbl t1where id = @idand not exists (select 1from tbl t2where t1.id = t2.id andt2.date > t1.date)Jayto here knows when |
 |
|
|
|
|
|