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


如表 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 where (a.phone,a.namein (

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

);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM