mysql: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

当执行mysql的update语句出现[You can’t specify target table ‘xxx’ for update in FROM clause]的报错的时候,其原因可能是:不能使用同一张表的查询内容来修改这张表,把原来表的内容作为一张临时表来处理就好了;
错误示例:update account a set a.leaguenum=(select count(id) from account where pid=10070) where a.id=10070;

正确写法:update account a set a.leaguenum=(select count(b.id) from (select id from account where pid=10070) as b) where a.id=10070;

猜你喜欢

转载自blog.csdn.net/wyg1995/article/details/88232141