1. 程式人生 > >mysql 查找除id外其他重復的字段數據

mysql 查找除id外其他重復的字段數據

one 我們 keyword pla 數據 plain image 多個 http

如表 test1 有多個重復的字段

技術分享

其中有些數據完全重復是錯誤的數據,我們要把他找出來,然後刪除掉

select * from test1 a where (a.phone,a.name) in (

select phone,name from test1 group by phone,name having count(*)>1

) and id not in (

select max(id) from test1 group by phone,name having count(*)>1

);

結果

技術分享

然後就可以用php或其他語言來刪除這些 id 了

或者

把前面的那個select換成

delete

delete from test1 a where (a.phone,a.name) in (

select phone,name from test1 group by phone,name having count(*)>1

) and id not in (

select max(id) from test1 group by phone,name having count(*)>1

);

mysql 查找除id外其他重復的字段數據