You can't specify target table 'agency' for update in FROM clause

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

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326596220&siteId=291194637