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 |
|
mike13
Posting Yak Master
219 Posts |
Posted - 2010-06-03 : 13:13:58
|
| Hi all,I want to select the Distinct Price from product table but i also want the product ID with itTableProductid,price1,10,002,23,003,24,004,35,005,10,006,10,007,23,008,24,009,35,0010,10,00I want it to return:1,10,002,23,003,24,004,35,00only distinct prices and the first product id it finds with that priceThanks a lot, |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-03 : 13:19:04
|
| [code]SELECT price,MIN(Productid)FROM TableGROUP BY price[/code] |
 |
|
|
mike13
Posting Yak Master
219 Posts |
Posted - 2010-06-04 : 01:56:34
|
quote: Originally posted by vijayisonly
SELECT price,MIN(Productid)FROM TableGROUP BY price
Thanks that did the Trick :-) |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-04 : 09:30:59
|
| Np. You're welcome. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-06-07 : 06:20:41
|
| use row_number function also....... |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-07 : 06:24:20
|
quote: Originally posted by bklr use row_number function also.......
Why? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-07 : 06:32:49
|
quote: Originally posted by webfred
quote: Originally posted by bklr use row_number function also.......
Why? No, you're never too old to Yak'n'Roll if you're too young to die.
I think he meant it as different approach as the question is posted in version 2005MadhivananFailing to plan is Planning to fail |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-06-07 : 06:43:06
|
quote: Originally posted by webfred
quote: Originally posted by bklr use row_number function also.......
Why? No, you're never too old to Yak'n'Roll if you're too young to die.
another way.... using row_number |
 |
|
|
|
|
|
|
|