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 |
srisha
Starting Member
38 Posts |
Posted - 2013-09-30 : 06:13:17
|
show to get lase updatded record --------------------------BYSRISHA |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-09-30 : 06:26:24
|
Assuming you've column called lastupdated you can use logic likeSELECT TOP 1 WITH TIES * FROM Table ORDER BY LastUpdated DESC to get all records which have greatest value of last updated date------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
marcusn25
Yak Posting Veteran
56 Posts |
Posted - 2013-10-07 : 17:05:38
|
Assuming you have [LastUpdateDate] date column from CustomerTableSELECT*From(SELECT Row_Number ()Over (Partition by CustomerID Order By LastUpdateDate desc) AS LastUpdate ,LastUpdateDate ,CustomerIDFROM Customer ) as CWhere C.LastUpdateDate = 1M. Ncube |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-07 : 23:33:58
|
quote: Originally posted by marcusn25 Assuming you have [LastUpdateDate] date column from CustomerTableSELECT*From(SELECT Row_Number ()Over (Partition by CustomerID Order By LastUpdateDate desc) AS LastUpdate ,LastUpdateDate ,CustomerIDFROM Customer ) as CWhere C.LastUpdateDate = 1M. Ncube
This will not return all records if there are multiple ones existing for the same maximum LastUpdateDate valuethis tweak will make it work though!SELECT*From(SELECT Dense_Rank ()Over (Partition by CustomerID Order By LastUpdateDate desc) AS LastUpdate ,LastUpdateDate ,CustomerIDFROM Customer ) as CWhere C.LastUpdate = 1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
marcusn25
Yak Posting Veteran
56 Posts |
Posted - 2013-10-10 : 19:29:30
|
Yes, you are right M. Ncube |
|
|
|
|
|