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
 Help needed with this type of Min/Max queries

Author  Topic 

kingjeremy
Starting Member

10 Posts

Posted - 2007-09-07 : 19:45:39
priceStockID productID supplierID price
1 1 1 100
2 1 2 110
3 2 1 10
4 2 3 20
5 3 1 30
6 3 2 20
7 3 3 15
8 4 1 40

how can I get the priceStockID for the lowest price of each product in the most efficient way

the result table should be like below



priceStockID productID supplierID price
1 1 1 100
3 2 1 10
7 3 3 15
8 4 1 40

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-07 : 19:51:09
What you are asking is very similar to this post: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=89062


Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

kingjeremy
Starting Member

10 Posts

Posted - 2007-09-08 : 19:16:56
Thanks for the reply the link helped to understand how to build a query regarding to my question, though I later realized that I had to build a more complex one cause I do not want a product returned more than once which in my sample question when prices are same for the same product from different suppliers it will return the same product more than one. Anyway I have to refine my question by adding more fields like commissionRate, supplierScore to reduce the possibility to get duplicate results.
Go to Top of Page
   

- Advertisement -