I have two tables:
1) Products - This has a list of different products.
1 - TV
2 - Radio
3 - Book
2) Retailers - This lists the retailer's prices for these products.
Amazon - TV - $100
Amazon - Radio - $60
Amazon - Book - $10
Play - TV - $90
Play - Radio - $50
Amazon - Book - $20
Tesco - TV - $120
Tesco - Radio - $30
Tesco - Book - $15
So after joining these two tables on the product name, I end up with multiple product listings like this:
1 - TV - Amazon - $100
1 - TV - Play - $90
1 - TV - Tesco - $120
2 - Radio - Amazon - $60
2 - Radio - Play - $50
2 - Radio - Tesco - $30
3 - Book - Amazon - $10
3 - Book - Play - $20
3 - Book - Tesco - $15
How would I go about writing a mysql statement that would return a table with only the lowest price for each individual product. So something that would look like this:
1 - TV - Play - $90
2 - Radio - Tesco - $30
3 - Book - Amazon - $10
Here's a simple version of my current mysql statement. Any ideas on how best to modify it to return just one listing of each product with the lowest price and its retailer?
1) Products - This has a list of different products.
1 - TV
2 - Radio
3 - Book
2) Retailers - This lists the retailer's prices for these products.
Amazon - TV - $100
Amazon - Radio - $60
Amazon - Book - $10
Play - TV - $90
Play - Radio - $50
Amazon - Book - $20
Tesco - TV - $120
Tesco - Radio - $30
Tesco - Book - $15
So after joining these two tables on the product name, I end up with multiple product listings like this:
1 - TV - Amazon - $100
1 - TV - Play - $90
1 - TV - Tesco - $120
2 - Radio - Amazon - $60
2 - Radio - Play - $50
2 - Radio - Tesco - $30
3 - Book - Amazon - $10
3 - Book - Play - $20
3 - Book - Tesco - $15
How would I go about writing a mysql statement that would return a table with only the lowest price for each individual product. So something that would look like this:
1 - TV - Play - $90
2 - Radio - Tesco - $30
3 - Book - Amazon - $10
Here's a simple version of my current mysql statement. Any ideas on how best to modify it to return just one listing of each product with the lowest price and its retailer?
Code:
SELECT * FROM products INNER JOIN retailers ON products.product = retailers.product
Comment