您的位置:首页 > 数据库 > MySQL

mysql删除重复记录

2017-06-16 11:01 197 查看
先查询重复记录值

select * from tbname where uid in (select uid from tbname group by uid having count(uid)>1);

能查询,应该就能删除

delete from tbname where uid in (select uid from tbname group by uid having count(uid)>1);

但是报错:You can't specify target table,意思是目标表不明确

修改sql语句,将查询结果放入一个临时表
delete from tbname where uid in (
select tmptb.uid(
select uid from tbname group by uid having count(uid)>1
) as tmptb
);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: