MySQL select DISTINCT by highest value

后端 未结 5 599
刺人心
刺人心 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:15

    None of the given answers are correct, as they return an disassociated set of data that does not represent one exact column. The id may not be the id from the same row as the onsale value.

    The following will work:

    SELECT
        id, onsale, magazine
    FROM (
        SELECT
           id, onsale, magazine
        FROM
            product
        ORDER BY
            onsale DESC) AS a
    GROUP BY
        magazine
    

提交回复
热议问题