我有以下查询返回所需的数据。我想要做的是删除该数据,但是当我将Select DQ。*更改为DELETE FROM DQ时,我收到错误消息,指示
'...不可更新,因为修改会影响多个基表'
我需要从tbaccess_groupPermission表中删除条目,其中在tbaccess_companyModules表中找不到相应的模块记录。
WITH DQ AS
(
SELECT GP.* FROM tbaccess_groupPermission GP
JOIN tbaccess_groups G ON GP.GroupID = G.ID
WHERE G.CompanyID=6
AND GP.RoleName NOT IN
(
select Distinct(R.RoleName)
FROM tbAccess_Roles R
INNER JOIN tbAccess_CompanyModules C on R.ModuleID = C.ModuleID
WHERE C.CompanyID = 6)
)
SELECT * FROM DQ
答案 0 :(得分:0)
为什么不更改WITH
语句以使用IN
子句?
像
这样的东西WITH DQ AS
(
SELECT GP.* FROM tbaccess_groupPermission GP
WHERE GP.GroupID IN (SELECT G.ID FROM tbaccess_groups G WHERE G.CompanyID=6)
AND GP.RoleName NOT IN
(
select Distinct(R.RoleName)
FROM tbAccess_Roles R
INNER JOIN tbAccess_CompanyModules C on R.ModuleID = C.ModuleID
WHERE C.CompanyID = 6)
)