暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

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

数据库SQL 2016-04-04
993

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,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论