这个问题在ORACLE是不会发生的,但是如果你使用的MYSQL,如果你在更新一个表的数据并且这个表的条件还是这个表的就会出现这个问题,比如:
UPDATE sys_datadict sd set sd.disabled =b'1' where sd.parent_id=
(
select s.id id from sys_datadict s where s.primaryKey='PAY_BACK_TYPE'
)
and sd.primaryKey='1';
这个时候就会引发出现You can't specify target table 'sd' for update in FROM clause
其实这个问题的解决方式是可以加一个中间表的,可以把SQL修改成这样就没有问题了:
UPDATE sys_datadict sd set sd.disabled =b'1' where sd.parent_id=(
select a.id from (
select s.id id from sys_datadict s where s.primaryKey='PAY_BACK_TYPE'
)a
) and sd.primaryKey='1';