- 时间:2022-04-16 16:07 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:Mysql删除重复的数据 Mysql数据去重复
[b]MySQL数据库中查询重复数据[/b]
select * from employee group by emp_name having count (*)>1;
[b]Mysql 查询可以删除的重复数据[/b]
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);
[b]Mysql 删除重复的数据[/b]
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);