The following query:
SELECT *
FROM productlist.pricelist_merchant
WHERE product_id <> '0'
ORDER BY
product_id ASC,
qty = 0,
price ASC;
Returns:
Merchant|product_id|price |qty|
Merch_A |3217 |44.30 |16 |
Merch_Z |3217 |45.14 |2 |
Merch_U |3217 |45.62 |16 |
Merch_I |3217 |46.06 |16 |
Merch_Q |3217 |48.98 |55 |
Merch_B |3217 |39.58 |0 |
Merch_T |3217 |45.97 |0 |
Merch_M |3217 |46.40 |0 |
Merch_L |3220 |105.84|1 |
Merch_Z |3220 |147.00|3 |
Merch_U |3220 |149.36|2 |
Merch_A |3220 |149.99|2 |
Merch_Q |3220 |153.53|90 |
Merch_I |3220 |154.51|2 |
Merch_T |3220 |157.41|4 |
Merch_C |3220 |164.59|46 |
Merch_M |3220 |136.10|0 |
Merch_B |3220 |136.71|0 |
Which is perfect for me. The product_id is sorted by price if there is qty available. But I need only the first row of a product_id. I would like to have this:
Merchant|product_id|price |qty|
Merch_A |3217 |44.30 |16 |
Merch_L |3220 |105.84|1 |
Only the first row of a product_id interests me. Is there a way to change my query to achieve this? I tried a lot of statements and none of it worked...
Thanks in advance!