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.
| Author |
Topic |
|
RichardSteele
Posting Yak Master
160 Posts |
Posted - 2012-05-03 : 17:35:44
|
| I'd like to query a database table that has some unique catalogids and some catalogids that are repeated multiple times, but only pull the lowest price item if they have the same catalogid. I need to keep the results in a uniqueorder sequence.So the basic query is this.Select uniqueorder, catalogid, price from inventory order by uniqueorder.What would a modified query look like that would only pull the item with the lowest price if they have the same catalogid?Thanks! |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2012-05-03 : 18:10:11
|
this?select i.uniqueorder, i.catalogid, x.minprice from inventory i join (select catalogid, min(price) as minprice from inventory group by catalogid) x on x.catalogid=i.catalogidorder by i.uniqueorder elsasoft.org |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-03 : 19:34:49
|
| [code]select uniqueorder, catalogid, pricefrom(Select uniqueorder, catalogid, price,row_number() over (partition by catalogid order by price) as rnfrom inventory)twhere rn=1order by uniqueorder[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|