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)  

posted @ 2019-09-26 10:26  带你走天涯  阅读(401)  评论(0编辑  收藏  举报