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
)
就可以了