MySQL Left Join + Min

前端 未结 4 1293
闹比i
闹比i 2020-12-14 08:52

Seemingly simple MySQL question, but I\'ve never had to do this before..

I have two tables, items and prices, with a one-to-many relationship.

Items         


        
4条回答
  •  清歌不尽
    2020-12-14 09:20

    Ok, how about?

    SELECT items.id, items.name, MIN(prices.price), prices.id
    FROM items 
    LEFT JOIN prices ON items.id = prices.item_id 
    GROUP BY items.id, MIN(prices.price)  
    

提交回复
热议问题