0

我有以下查询,它返回所需的数据。我想要做的是删除该数据,但是当我将 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
4

1 回答 1

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) 
) 
于 2013-09-02T17:34:01.133 回答