MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause
2017年03月21日 11:32:46 回归心灵 阅读数:686
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010657094/article/details/64439486
当执行以下sql语句时会出现 Error Code:1093 错误:
update car set tag = 1 where id in (select id from car where brand_id=182 and tag=0);
- 1
出现错误的原因是因为修改的表和查询的表是同一个表,MySQL是不允许这样做的,我们可以通过中间再查询一次来解决:
update car set tag = 1 where id in (select id from (select id from car where brand_id=182 and tag=0) As temp);