首页 > 数据库 > MySQL > 正文

Mysql删除重复的数据 Mysql数据去重复

2024-07-24 12:53:46
字体:
来源:转载
供稿:网友

MySQL数据库中查询重复数据

select * from employee group by emp_name having count (*)>1;

Mysql  查询可以删除的重复数据

select t1.* from employee t1 where (t1.emp_name) in (select t4.emp_name from (select t2.emp_name from employee t2 group by t2.emp_name having count(*)>1) t4) and t1.emp_id not in (select t5.emp_id from (select min(t3.emp_id) as emp_id from employee t3 group by t3.emp_name having count(*)>1) t5);

Mysql  删除重复的数据

delete t1 from employee t1 where (t1.emp_name) in (select t4.emp_name from (select t2.emp_name from employee t2 group by t2.emp_name having count(*)>1) t4) and t1.emp_id not in (select t5.emp_id from (select min(t3.emp_id) as emp_id from employee t3 group by t3.emp_name having count(*)>1) t5);

您可能感兴趣的文章:

MySQL去重的方法整理mysql去重的两种方法详解及实例代码mysql 开发技巧之JOIN 更新和数据查重/去重一条sql语句完成MySQL去重留一
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表