Mysql
 sql >> Database >  >> RDS >> Mysql

Come creare un join distinto con MySQL

Usa:

   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