作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试对满足特定条件的值执行更新操作。我的表 CAPD、CAMP、CAD
。但是我得到了错误
Error Code: 1093. You can't specify target table 'CAPD' for update in FROM clause
UPDATE CAPD SET CAPD.Is_Active = 1
WHERE CAPD.Per_Id IN (
SELECT CAMP.Id
FROM CAMP
INNER JOIN CAPD ON (
CAPD.Per_Id = CAMP.Id
AND CAPD.Is_Active = 0
)
INNER JOIN CAD ON (
CAD.Id = CAPD.Deploy_Id
AND BINARY CAD.Access_Id = "486579446F6E277-4436F6E7665727449742E2E4C-4F4C203A5020584F586F"
)
WHERE CAMP.Serial = "ABC1230071"
)
最佳答案
You cannot use the target table which you are updating inside the subquery. You need to use the JOIN in case you want to use it -- First answer by @Rahul Tripathi
你必须尝试这个查询然后你需要设置SET SQL_SAFE_UPDATES
SET SQL_SAFE_UPDATES=0;
UPDATE CAPD
INNER JOIN CAD ON ( CAD.Id = CAPD.Deploy_Id)
SET CAPD.Is_Active = 1
WHERE CAPD.Per_Id IN (
SELECT CAMP.Id
FROM CAMP
WHERE CAMP.Serial = "ABC1230071"
)
AND BINARY CAD.Access_Id = "486579446F6E277-4436F6E7665727449742E2E4C-4F4C203A5020584F586F";
SET SQL_SAFE_UPDATES=1;
关于MySql 更新 : Can't specify target table for update in FROM clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33564300/
我是一名优秀的程序员,十分优秀!