How to make a “distinct” join with MySQL

前端 未结 5 1024
悲&欢浪女
悲&欢浪女 2021-02-05 04:14

I have two MySQL tables (product and price history) that I would like to join:

Product table:

Id = int
Name = varchar
Manufacturer = varchar         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 04:52

    Why not keep it simple and fast:

    SELECT 
     Product.UPC, Product.Name, Price_h.Price, Price_h.Date
    FROM 
     Product
    LEFT JOIN 
     Price_h
     ON Product.Id = Price_h.Product_id;
    ORDER BY
     Price_h.Date DESC
    LIMIT 1
    

提交回复
热议问题