分类 MySQL 下的文章

查询 group_source 表中 name 字段的值重复的记录

select * from group_source where name in
     (select name from group_source group by name having count(name)>1);

删除重复的数据,并且保留ID最小的记录

delete from group_source where name in
     (select name from

          (select name from group_source group by name having count(name)>1) as data1)

and id not in

      (select id from

          (select min(id) from group_source group by name having count(name)>1) as data22);