当执行以下sql语句时会出现 Error Code:1093 错误:
update car set tag = 1 where id in (select id from car where brand_id=182 and tag=0);
出现错误的原因是因为修改的表和查询的表是同一个表,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);