mysql-You can’t specify target table for update in FROM clause错误
mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)
例如
delete from table名称 where idStr in ( select h.idStr from table名称 h
group by h.otherKey
having count(1) >1
);
就会报上面的错误
改
delete from table名称 where idStr in ( select s.idStr from (
select h.idStr, h.otherKey,count(1) c from table名称 h group by h.otherKey ) s where s.c >1 );
通过中间临时表来执行即可解决问题
知识只有共享才能传播,才能推崇出新的知识,才能学到更多,这里写的每一篇文字/博客,基本都是从网上查询了一下资料然后记录下来,也有些是原滋原味搬了过来,也有时加了一些自己的想法