mysql更新表数据时报错 You can't specify target table 'RES_CATALOG_CLASSIFY' for update in FROM clause

You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据。

将sql语句

UPDATE RES_CATALOG_CLASSIFY
SET CATALOG_SORT = CATALOG_SORT + 1
WHERE
    ID = (
        SELECT
            ID
        FROM
            `res_catalog_classify`
        WHERE
            PARENT_ID = '001'
        AND CATALOG_SORT = 7
    )

改为

UPDATE RES_CATALOG_CLASSIFY
SET CATALOG_SORT = CATALOG_SORT + 1
WHERE
    ID = (
        SELECT a.ID FROM (SELECT
            ID
        FROM
            `res_catalog_classify`
        WHERE
            PARENT_ID = '001'
        AND CATALOG_SORT = 7) a
    )

就可以了

posted @ 2018-11-06 10:58  無玑小姐  阅读(280)  评论(0编辑  收藏  举报