MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause

MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause

版权声明:本文为博主原创文章,未经博主允许不得转载。 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);

posted on 2018-11-07 11:33  David_Deng  阅读(1369)  评论(0编辑  收藏  举报

导航