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
 Other SQL Server Topics (2005)
 selecting the max data

Author  Topic 

taniarto
Starting Member

27 Posts

Posted - 2013-07-08 : 23:33:09
I Have data :

ID Nname qty
001 car 100
002 Bus 50
003 Truck 20
004 van 10

I want to show only the latest record or max record. what is the syntax
so it can show :

004 Van 10

thanks

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 MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

taniarto
Starting Member

27 Posts

Posted - 2013-07-10 : 04:13:38
if there were record like :
ID Qty
001 100
001 200
002 200
002 300
003 50
003 150
003 200

I want to display only the max value of the record. So the result can display like :
ID Qty
001 200
002 300
003 200

thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-10 : 05:06:20
[code]
SELECT ID,Qty
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY ID ORDER BY Qty DESC) AS Seq,*
FROM Table
)t
WHERE Seq=1
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -