How to group by DESC order

后端 未结 7 1964
终归单人心
终归单人心 2020-12-03 06:30

I have the following table called questions:

ID | asker 
1  | Bob
2  | Bob
3  | Marley

I want to select each asker only once and if there are

7条回答
  •  春和景丽
    2020-12-03 07:03

    It's because ORDER BY is performed AFTER GROUP BY.

    Try this:

    SELECT * FROM questions
    WHERE id IN 
    (
        SELECT max(id) as id
        FROM questions 
        GROUP by asker 
        ORDER by id DESC
    )
    

提交回复
热议问题