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 |
taniarto
Starting Member
27 Posts |
Posted - 2013-07-08 : 23:33:09
|
I Have data :ID Nname qty001 car 100002 Bus 50003 Truck 20004 van 10I want to show only the latest record or max record. what is the syntaxso it can show :004 Van 10thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-09 : 01:24:23
|
[code]SELECT TOP 1 *FROM Table ORDER BY (ID*1) DESC[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
taniarto
Starting Member
27 Posts |
Posted - 2013-07-10 : 04:13:38
|
if there were record like :ID Qty001 100001 200002 200002 300003 50003 150003 200I want to display only the max value of the record. So the result can display like :ID Qty001 200002 300003 200thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-10 : 05:06:20
|
[code]SELECT ID,QtyFROM(SELECT ROW_NUMBER() OVER (PARTITION BY ID ORDER BY Qty DESC) AS Seq,*FROM Table)tWHERE Seq=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|