sql >> Base de Datos >  >> RDS >> Mysql

Cómo hacer una combinación distinta con MySQL

Usar:

   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