mysql 数据表中查找重复记录

时间:2021-12-22 22:17:36

1、单个字段

查询所有重复数据

select * from ActivityWinUser where (UID) in(select UID from ActivityWinUser group by UID having count(*)>1);

去重

delete from table where Name in(select Name from table group by Name having count(*)>1);

2、多个字段

查询所有重复数据

select * from table a where (a.UID,a.ActivityID)  in (select UID,ActivityID from table group by UID,ActivityID having count(*) > 1) ;

3、去除重复记录

select *, count(distinct name) from table group by name