I have a table instructor and I want to delete the records that have salary in a range
An intuitive way is like this:
delete from instructor where salary between 13000 and 15000;
However, under safe mode, I cannot delete a record without providing a primary key(ID).
So I write the following sql:
delete from instructor where ID in (select ID from instructor where salary between 13000 and 15000);
However, there is an error:
You can't specify target table 'instructor' for update in FROM clause
I am confused because when I write
select * from instructor where ID in (select ID from instructor where salary between 13000 and 15000);
it does not produce an error.
My question is:
- what does this error message really mean and why my code is wrong?
- how to rewrite this code to make it work under safe mode?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…