根据下级状态更新上级状态

原来语句

SET display = 1
WHERE
    id IN (
        SELECT
            a.pid
        FROM
            area a
        WHERE
            a.display = 1
        AND pid != 0
    );

Copy

提示:\[Err] 1093 – You can’t specify target table ‘area’ for update in FROM clause

修改后

UPDATE area a1,(
        SELECT
            pid
        FROM
            area
        WHERE
            display = 1
        AND pid != 0
    ) a2
SET a1.display = 1
where a1.id=a2.pid;

本条目发布于[2020年4月17日](https://c4ys.com/archives/2121 "11:15")。属于[Database](https://c4ys.com/archives/category/database)分类,被贴了 [mysql](https://c4ys.com/archives/tag/mysql) 标签。