I have a table instructor and I want to delete salary entries in a range Intuitive way:
delete from instructor where salary between 13000 and 15000;
However, in safe mode, I cannot delete the record without providing a primary key (ID).
So, I am writing 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'm confused because when I write
select * from instructor where ID in (select ID from instructor where salary between 13000 and 15000);
it does not cause an error.
My question is:
- What does this error message really mean and why is my code incorrect?
- How to rewrite this code so that it works in safe mode?
Thank!
sql mysql
roland luo Feb 17 '14 at 23:25 2014-02-17 23:25
source share