How to group by DESC order

后端 未结 7 1969
终归单人心
终归单人心 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:08

    The records need to be grouped using GROUP BY and MAX() to get the maximum ID for every asker.

    SELECT  asker, MAX(ID) ID
    FROM    TableName
    GROUP   BY asker
    
    • SQLFiddle Demo

    OUTPUT

    ╔════════╦════╗
    ║ ASKER  ║ ID ║
    ╠════════╬════╣
    ║ Bob    ║  2 ║
    ║ Marley ║  3 ║
    ╚════════╩════╝
    

提交回复
热议问题