Get list of duplicate rows in MySql

前端 未结 4 792
忘了有多久
忘了有多久 2021-02-04 19:01

i have a table like this

ID     nachname     vorname
1       john         doe
2       john         doe
3       jim          doe
4       Michael     Knight
         


        
4条回答
  •  独厮守ぢ
    2021-02-04 19:32

    select * from table AS t1 inner join
    (select max(id) As id,nachname,vorname, count(*) 
    from t1 group by nachname,vorname 
    having count(*) >1) AS t2 on t1.id=t2.id
    

    This should return ALL of the columns from the table where there is duplicate nachname and vorname. I recommend changing * to the exact columns that you need.

    Edit: I added a max(id) so that the group by wouldn't be a problem. My query isn't as elegant as I would want though. There's probably an easier way to do it.

提交回复
热议问题