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

1 queries executed, 0 success, 1 errors, 0 warnings

Query: delete from area_post_code where id in ( SELECT b.id FROM `area_post_code` b WHERE (b.id,b.`name`) NOT IN (SELECT id ,`name` FRO...

Error Code: 1093
You can't specify target table 'area_post_code' for update in FROM clause

Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0 sec

不能先select出同一表中的某些值,再update这个表(在同一语句中),所以在子查询的select中在套一层select

sql修改:

DELETE FROM area_post_code WHERE id IN (
    SELECT aa.id FROM (
        SELECT b.id AS id FROM `area_post_code` b WHERE (b.id,b.`name`) NOT IN (SELECT id ,`name` FROM `atest`) 
        AND b.id NOT IN ('310100','310000','110000','110100', '120000','120100', '510000','500100','100000')
    ) aa
) 

 

posted @ 2021-05-13 19:01  wujingqi  阅读(52)  评论(0编辑  收藏  举报