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
 General SQL Server Forums
 New to SQL Server Programming
 get min
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ktkn
Starting Member

13 Posts

Posted - 12/04/2012 :  15:47:07  Show Profile  Reply with Quote
I have tbl_sale table below with two columns

orderNo purchaseNo
123 50
123 10
456 20
789 40

There are many purchaseNo within the table and don't know what is the min value is. I have the query below to get the min number for particular orderNo but not sure if mine sysntax is correctted?
The result i want is
orderNo purchaseNo
123 10


Thanks

SELECT orderNo, purchaseNo
FROM tbl_sale
where purchaseNo =
(SELECT MIN(purchaseNo)
FROM tbl_sale where
orderNo = 123)
and orderNo = 123

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/04/2012 :  15:57:21  Show Profile  Reply with Quote
select orderno,min(purchaseNo)
from tbl_sale
group by orderno
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.12 seconds. Powered By: Snitz Forums 2000