您的位置:首页 > 数据库 > MySQL

You can't specify target table 'test' for update in FROM clause.

2017-07-19 00:00 375 查看
You can't specify target table 'test' for update in FROM clause.

MySQL中You can't specify target table <test> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。 例如下面这个sql:

update test set `status`=3 where id in(select * from test where status=-50);

改写成下面就行了:

update test set `status`=3 where id in(select a.id from (select * from test where status=-50) a);

也就是说将select出的结果再通过中间表select一遍,这样就规避了错误。注意,这个问题只出现于mysql,mssql和Oracle不会出现此问题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MySQL
相关文章推荐