MySQL删除重复数据保留一条,该怎么办?

1、查找表中的多余的重复记录,重复记录是根据单个字段(empID)来判断


select * from Employee where EmpID in (select EmpID from Employee group by EmpID having count(EmpID)>1 )

2、删除表中多余的重复记录,重复记录是根据单个字段(empID)来判断,,


select * from Employee where EmpID in (select EmpID from Employee group by EmpID having count(EmpID)>1 )

多字段:

1、选择:

select * from vitae emp where (emp.empID,emp.seq) in (select empID,seq from vitae group by empID ,seq having count(*) >1)


2、删除

delete from employee where empName in(select empName from employee group by empName having count(empName)>1) and empID not in (select min(empID) from employee group by empName having count(empName)>1 )


原文发布于微信公众号 - 数据库SQL(SQLdba)

原文发表时间:2016-04-04

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区