mysql之删除重复数据_MySQL
程序员文章站
2022-06-15 16:35:07
...
//删除id重复的数据,适合id是手工主键
delete person as a from person as a,
(
select *,min(id) from person group by id having count(1) > 1
) as b
where a.id = b.id
(
select *,min(id) from tb_person group by name having count(1) > 1
) as b
where a.name = b.name and a.id > b.id;
delete person as a from person as a,
(
select *,min(id) from person group by id having count(1) > 1
) as b
where a.id = b.id
//查找重复的,并且除掉最小的那个delete tb_person as a from tb_person as a,
(
select *,min(id) from tb_person group by name having count(1) > 1
) as b
where a.name = b.name and a.id > b.id;