You cant specifty target table xxx for update in FROM clause

如果mysql更新,删除语句的条件依赖子查询语句的结果,此时就需要注意了,不然就会报出"You can't specifty target table xxx for update in FROM clause"的问题:

例如以下语句:

delete from student where id in (select id from student where LENGTH(id)>32);

执行后报出上述错误,大意是说你不能update操作某表在子查询语句中,也就是说对某个表进行查询操作的同时不能对其进行更新,我们可以将查询结果存入一个临时表,然后进行更新或删除;

delete from student where id in (select id from (select id from student where LENGTH(id)>32) c);

更新操作中嵌套子查询也是如此;

Guess you like

Origin blog.csdn.net/u011821510/article/details/113605168