mysql 出现You can't specify target table for update in FROM clause错误的解决方法

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

 

原语句:


update t_users set coins = (coins +1)   where userid=126;

 

 

修改之后的:


update t_users set coins = ( select ub.a from (select (coins+1) a from t_users where userid=126) ub )where userid=126;

 

posted @ 2021-05-21 15:57  2538  阅读(615)  评论(0编辑  收藏  举报