在mysql中更新数据,出现You can't specify target table for update in FROM clause错误,这句话意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。
例如下面这个sql:
update A set update_time =now(), is_enable = 1, update_user = 1 where id in (
select id from A where status = 3 and is_stoped = 0 and commodity_id in (
select id from B where code in ('1.12.012.66'))
)
就会报以上的错误,这时候我们只需要修改成下面就可以了,
update A set update_time =now(), is_enable = 1, update_user = 1 where id in (
select id from (
select id from A where status = 3 and is_stoped = 0 and commodity_id in (
select id from B where code in ('1.12.012.66'))) t
)
在oracle就不会出现上面的错误。