如何删除Mysql表中的重复记录呢?最容易想到的直接办法(假设我想删除字段orderNum中的重复项):
delete from cbfinancials where id in
(select id from cbfinancials group by orderNum having count(1)>1);
但遗憾的是这样写Mysql会提示错误:You can't specify target table 'cbfinancials ' for update in FROM clause
我们可以这样来解决:
delete from cbfinancials where id in
(select tmp.id from (select * from cbfinancials) as tmp
group by orderNum having count(1)>1);
把两个表分开,第二个用临时表,避免select和delete为同一个表,这样就不会报错了。
已经有(0)位网友发表了评论,你也评一评吧!
原创文章如转载,请注明:转载自Eddy Blog
原文地址:http://www.rrgod.com/technique/870.html 欢迎订阅Eddy Blog。
Tags:Mysql