MySQL select DISTINCT by highest value

后端 未结 5 564
刺人心
刺人心 2021-01-05 06:52

I have a table full of magazines, and need to extract the latest unique issue of each magazine.

Ive tried

    SELECT DISTINCT
    magazine
        F         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 07:26

    This looks like what you need:

    SELECT id, MAX(onsale) AS onsale, magazine FROM magazines GROUP BY magazine ORDER BY onsale DESC;
    

    Check it out at:

    http://sqlfiddle.com/#!2/38e78/3

    UPDATE: I've changed query a little, to return MAX(onsale)

提交回复
热议问题