标签:
执行下面sql报错[Err] 1093 - You can‘t specify target table ‘uu‘ for update in FROM clause:
UPDATE sellmanagement_agency_user uu
SET uu.`status` = 1
WHERE
uu.id IN (
SELECT
u.id
FROM
sellmanagement_agency_user u
LEFT JOIN sellmanagement_agency_type t ON u.type_id = t.id
WHERE
t.type = 3
AND u.`status` = 0
)
select出的结果再通过中间表select一遍,这样就规避了错误。注意,这个问题只出现于mysql,mssql和oracle不会出现此问题。
改成下面sql成功:
UPDATE sellmanagement_agency_user uu
SET uu.`status` = 1
WHERE
uu.id IN (
SELECT u.id from (
SELECT
u.id
FROM
sellmanagement_agency_user u
LEFT JOIN sellmanagement_agency_type t ON u.type_id = t.id
WHERE
t.type = 3
AND u.`status` = 0
) u
)
标签:
原文地址:http://www.cnblogs.com/duyunpeng1992/p/4485498.html