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
 General SQL Server Forums
 New to SQL Server Programming
 get min

Author  Topic 

ktkn
Starting Member

13 Posts

Posted - 2012-12-04 : 15:47:07
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
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-04 : 15:57:21
select orderno,min(purchaseNo)
from tbl_sale
group by orderno
Go to Top of Page
   

- Advertisement -