update image set state=2
where id in ( select img.id from image img inner join imageauditing imd on img.id=imd.imageid where img.state=1)
在mysql中使用上面的语句执行修改时会出现错误([Err] 1093 - You can't specify target table 'image' for update in FROM clause)
这个错误是因为当你修改这个表时 同时也查询了这个表
解决方法如下:
把需要修改的数据查询出来作为第三方表
update image set state=2
where id in ( select t.id from (select img.id from image img inner join imageauditing imd on img.id=imd.imageid where img.state=1) t)