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 |
|
xarrisx
Starting Member
3 Posts |
Posted - 2010-06-22 : 04:33:51
|
| this is an exaple tableprodid | prodqty | prodprice | 1 2 50 2 5 60 1 4 75 1 1 30 2 2 25what i want to do is select a table withdistinct(prodid) | min(prodqty) | prodprice(of min(prodqty))it should return1 | 1 | 302 | 2 | 25i tried withSELECT prodid, min(prodqty),prodpricefrom productsgroup by prodidbut not workingAny help and explanation about why the code not working would be highly appreciated!Thanks in advance |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-22 : 04:42:32
|
| SELECT t1.prodid, t1.prodqty,t1.prodpricefrom products as t1 inner join(SELECT prodid, min(prodqty) as prodqtyfrom productsgroup by prodid) as t2on t1.prodif=t2.prodid and t1.prodqty=t2.prodqtyMadhivananFailing to plan is Planning to fail |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-06-22 : 04:44:40
|
| What do you mean by 'not working'? Throws an error? (if so, what error?) Produces incorrect results? (If so, what is it returning?)--Gail ShawSQL Server MVP |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-22 : 04:44:50
|
| orselect * from(select *,row_number() over (partition by prodid order by prodqty) as sno from products) as twhere sn=1MadhivananFailing to plan is Planning to fail |
 |
|
|
xarrisx
Starting Member
3 Posts |
Posted - 2010-06-24 : 06:00:22
|
| thanks a lot madhivananfirst solution working-I have to do a little research on this one(very advanced!-for me)second solution contains duplicated valuesthanks again |
 |
|
|
xarrisx
Starting Member
3 Posts |
Posted - 2010-06-24 : 06:09:18
|
| second solutionis also okMy fault it produced duplicated values |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-24 : 06:10:25
|
quote: Originally posted by xarrisx second solutionis also okMy fault it produced duplicated values
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|