mysql删除数据库表中重复数据(根据单个或多个字段)

时间:2022-04-14 20:12:55

mysql删除数据库表中重复数据(根据单个或多个字段)
通过单个字段(name)删除:delete from user where id not in
(
select id from
(
select max(id) id from user group by name
) a
);

通过多个字段(name,age)删除:delete from user where id not in
(
select id from
(
select max(id) id from user group by name,age
) a
);

其实差不多啦,不过这么写sql效率很低,欢迎大家有什么高效的写法教给我,谢谢啦!