Mysql数据库删除表中重复数据且只保留一条

删除重复数据并且只保留一条

delete
from sys_role
where code in (
select aaa.codee
from (
select code as codee
from sys_role
group by code
having count(code) > 1
) aaa)
and id not in
(select bbb.iddd
from (
select min(id) as iddd
from sys_role
group by code
having count(code) > 1) bbb)
;

发布了48 篇原创文章 · 获赞 15 · 访问量 1343

猜你喜欢

转载自blog.csdn.net/Bzbtyhydcxy/article/details/103922484