mysql刪除重複記錄

如:現有一張表名爲trojans,其中others字段很多是重複的,

刪除重複的記錄語句如下:

 

delete trojans from trojans , (select id from trojans GROUP by others having count(*)>1) as t2 where t2.id=trojans.id

這個語句一次只能刪除重複中的一條記錄,所以如果有n個重複記錄就要執行n-1遍

 

 

 

 

多字段分組

delete pcap from pcap ,(select id from pcap group by createdtime,horse,horseprot,horseregion having count(*) >1)as p2 where p2.id=pcap.id

發佈了32 篇原創文章 · 獲贊 15 · 訪問量 61萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章