I have two MySQL tables (product and price history) that I would like to join:
Product table:
Product
Id = int Name = varchar Manufacturer = varchar
Use:
SELECT p.upc, p.name, ph.price, ph.date FROM PRODUCT p LEFT JOIN PRICE_H ph ON ph.product_id = p.id JOIN (SELECT a.product_id, MAX(a.date) AS max_date FROM PRICE_H a GROUP BY a.product_id) x ON x.product_id = ph.product_id AND x.max_date = ph.date