Jump to content

[SOLVED] How do I select only the lowest price for each unique ID?


daydreamer

Recommended Posts

Hi,

 

I have a table:

 

---tblPrices---

ID, Price, Product ID

1    22    106

2    25    106

3    19    106

4    88    107

5    77    107

 

I want to select only the lowest price for each unique product ID in one SQL call, how do I do it?!

 

Thanks.

 

And if you want the actual rows with the minimum in each group (not just the minimum value in a group) you will need to use one of the methods at the following link (alter the code to use the MIN() function as needed) - http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html

Thanks for the solutions, my actual SQL had a left join in it so the normal

SELECT ID, MIN(Price) FROM tblPrices GROUP BY Product ID

 

wasnt working.

 

And if you want the actual rows with the minimum in each group (not just the minimum value in a group) you will need to use one of the methods at the following link (alter the code to use the MIN() function as needed) - http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html

 

This sorted it, Cheers

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.