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

你可能感兴趣的:(mysql,delete)