Get list of duplicate rows in MySql

前端 未结 4 801
忘了有多久
忘了有多久 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:47

    You can do it with a self-join:

    select distinct t1.id from t as t1 inner join t as t2 
    on t1.col1=t2.col1 and t1.col2=t2.col2 and t1.id<>t2.id
    

    the t1.id<>t2.id is necessary to avoid ids matching against themselves. (If you want only 1 row out of each set of duplicates, you can use t1.id).

提交回复
热议问题