You can't specify target table 'e' for update in FROM clause

Posted mryangbo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了You can't specify target table 'e' for update in FROM clause相关的知识,希望对你有一定的参考价值。

 

UPDATE emp e SET e.salary=e.salary+7 WHERE e.id IN(SELECT e1.id FROM emp e1,dept d WHERE e1.dep_id=d.id AND d.name=‘开发一部‘ AND e1.salary<2000);

不能先select出同一表中的某些值,再update这个表(在同一语句中)。

mysql 中会出现这个问题。

改写:

UPDATE emp e SET e.salary=e.salary+7 WHERE e.id IN(

  SELECT w.* FROM(

    SELECT e1.id FROM emp e1,dept d WHERE e1.dep_id=d.id AND d.name=‘开发一部‘ AND e1.salary<2000

    ) w

);

以上是关于You can't specify target table 'e' for update in FROM clause的主要内容,如果未能解决你的问题,请参考以下文章

You can't specify target table 'table' for update in FROM clause

You can't specify target table 'xxx' for update in FROM clause

mysql You can't specify target table 'xxx' for update in FROM clause的解决

You can't specify target table 't_mail_marketing' for update in FROM clause

You can't specify target table '表名' for update in FROM clause”解决方法

You can't specify target table 'e' for update in FROM clause