SQL duplicates with different primary keys

前端 未结 7 1333
青春惊慌失措
青春惊慌失措 2021-01-24 19:56

I have a table in this form:

id | firstname | lastname
---+-----------+----------
1  | alex      | marti
2  | mark      | finger
3  | alex      | marti
4  | ted          


        
7条回答
  •  礼貌的吻别
    2021-01-24 20:48

    you can do the following to show all the id column values

    SELECT GROUP_CONCAT(DISTINCT id SEPARATOR ',') AS ids, firstname, lastname FROM t GROUP BY firstname, lastname HAVING COUNT(*) > 1
    

    This should show something like this:

    ids | firstname | lastname
    ----+-----------+----------
    1,3 | alex      | marti
    

提交回复
热议问题