SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 selecting the max data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

taniarto
Starting Member

Indonesia
27 Posts

Posted - 07/08/2013 :  23:33:09  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 07/09/2013 :  01:24:23  Show Profile  Reply with Quote

SELECT TOP 1  *
FROM Table 
ORDER BY (ID*1) DESC


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

taniarto
Starting Member

Indonesia
27 Posts

Posted - 07/10/2013 :  04:13:38  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 07/10/2013 :  05:06:20  Show Profile  Reply with Quote

SELECT ID,Qty
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY ID ORDER BY Qty DESC) AS Seq,*
FROM Table
)t
WHERE Seq=1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000