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

错误信息:You can't specify target table 'XXX' for update in FROM clause

分析:无法执行,为什么?

度娘+谷哥:

mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。

总结来说就是:套一层,使用别名把。

举例:

错误:update a set status=1 where (select * from a where type=1)  

修正:update a set status=1 where (select  b.*  from(select * from a where type=1) b)  

原文地址:https://www.cnblogs.com/potatoChicken/p/11589308.html