查询出所有重复记录
select 字段名,字段名 from 表名 where 重复字段名 in (select 重复字段名 from 表名 group by 重复字段名 having count(1) >= 2) ORDER BY 重复字段名
查询出所有重复记录并且删除多余的只保留一条
delete from 表名 where 重复字段名 in ( SELECT a.重复字段名from( select 重复字段名 from 表名 group by 重复字段名 having count(1) > 1 ) a ) and id(只保留id最小的一个) not in ( SELECT b.id from( select min(id) as id from 表名 group by 重复字段名 having count(1)>1 ) b )
本文为仙士可原创文章,转载无需和我联系,但请注明来自仙士可博客www.php20.cn
翟鳳璽:感谢博主
2021-08-23 17:09:48 回复