DELETE a from nature_product a
JOIN (
select count(*) as count,custom_code,MIN(id) as id
from nature_product GROUP BY custom_code HAVING count >1
) b on a.custom_code = b.custom_code and a.id > b.id
mysql删除重复数据sql
本文介绍了一种使用SQL语句从数据库中删除重复记录的方法。通过一个子查询连接到主表,选择具有相同custom_code但ID不是最小的那个记录进行删除,确保每个custom_code只保留一条记录。

被折叠的 条评论
为什么被折叠?



