Mysql 删除重复数据

1、如果只有一个字段数据重复

自关联,保留id最小的那一条,其它的都删除
DELETE t1 
FROM
    user t1,
    user t2 
WHERE
    t1.user_code = t2.user_code 
    AND t1.id > t2.id;

2、如果是全部字段都相同

delete from user where user_code in (
select user_code from (
select user_code from user
group by user_code 
HAVING count(user_code ) > 1) t) limit 1;

 

 

参考:https://blog.csdn.net/qq_41602468/article/details/119010077

https://www.cnblogs.com/cjsblog/p/16401882.html

posted @ 2022-07-01 09:51  唏嘘-  阅读(1050)  评论(0编辑  收藏  举报