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 |
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-04-06 : 10:41:12
|
Hi,Let's say i've following table,tblRegDteAssetID | ReNewDte | EndDte-------------------------------------1631 | 4/13/2005 | 4/12/20091631 | 4/13/2001 | 4/12/20051223 | 7/13/2005 | 7/12/20091629 | 4/13/1998 | 4/12/20021629 | 4/13/2006 | 4/12/20101629 | 4/13/2002 | 4/12/20061622 | 4/13/2002 | 4/12/2006........How SQL look's like to display only latest date on EndDte on each AssetID.My expected result as follow,AssetID | ReNewDte | EndDte-------------------------------------1631 | 4/13/2005 | 4/12/20091223 | 7/13/2005 | 7/12/20091629 | 4/13/2006 | 4/12/20101622 | 4/13/2002 | 4/12/2006........ |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-04-06 : 10:47:53
|
Look up MAX() in Books Online. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-06 : 10:50:57
|
select * from your_table as t where EndDte=(select max(EndDte) from your_table where AssetID=t.AssetID and ReNewDte=t.ReNewDte)MadhivananFailing to plan is Planning to fail |
|
|
dsindo
Starting Member
45 Posts |
Posted - 2009-04-10 : 14:58:03
|
select AssetID, max(ReNewDte) as ReNewDte, max(EndDte) as EndDte from tblRegDte group by AssetID |
|
|
dsindo
Starting Member
45 Posts |
Posted - 2009-04-10 : 15:07:10
|
select * from tblRegDte ainner join ( select assetid, max(enddte) as enddte from tblRegDte group by assetid ) b on a.assetid=b.assetid and a.enddte=b.enddte |
|
|
|
|
|