我有一位表讲师,我想删除工资范围在一定范围内的记录。一种直观的方式是这样的:
delete from instructor where salary between 13000 and 15000;
但是,在安全模式下,如果不提供主键(ID),则无法删除记录。
所以我写下面的sql:
delete from instructor where ID in (select ID from instructor where salary between 13000 and 15000);
但是,有一个错误:
You can't specify target table 'instructor' for update in FROM clause
我很困惑,因为当我写
select * from instructor where ID in (select ID from instructor where salary between 13000 and 15000);
它不会产生错误。
我的问题是:
- 此错误消息的真正含义是什么,为什么我的代码错误?
- 如何重写此代码以使其在安全模式下工作?
谢谢!