Mysql execute delete statement
DELETE FROM agency WHERE id in(
SELECT b.id from agency b WHERE b.stateId in(
SELECT a.ID from states a WHERE a.saved=0 or a.saved=-1
)
)
出现You can't specify target table 'agency' for update in FROM clause错误,
Solution:
DELETE FROM agency WHERE id in(
SELECT aaaa.id from(
SELECT b.id from agency b WHERE b.stateId in(
SELECT a.ID from states a WHERE a.saved=0 or a.saved=-1
)
) aaaa
)
That is to say, the result of the select is selected again through the intermediate table