Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 get min
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

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


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

Flowing Fount of Yak Knowledge

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  
 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.02 seconds. Powered By: Snitz Forums 2000