有2个联接的SQL删除吗?

时间:2018-10-30 09:31:01

标签: sql sql-delete

我必须删除一个已禁用用户的表。问题是,我必须在最后使用where子句。这是最重要的一点,因为否则我无法测试我的查询。

where子句很重要,因为如果没有子句,我将删除整个数据库,而不仅是禁用的用户。

DELETE a
   FROM CONTENT_PERM a
   JOIN user_mapping b
     ON a.USERNAME = b.USER_KEY
        (JOIN CWD_USER c
           ON b.USERNAME = c.USER_NAME)
  WHERE c.ACTIVE = 'F';

3 个答案:

答案 0 :(得分:0)

如果我理解正确,那么您不需要在()之间加入JOIN

DELETE a
FROM CONTENT_PERM a
JOIN user_mapping b
ON a.USERNAME = b.USER_KEY
JOIN CWD_USER c
ON b.USERNAME = c.USER_NAME
WHERE c.ACTIVE = 'F';

答案 1 :(得分:0)

只需使用Select Query,只需删除Delete并检查您是否获得了正确的结果,然后根据结果可以采取措施删除查询。 如下所示。

Select a
FROM CONTENT_PERM a
JOIN user_mapping b
ON a.USERNAME = b.USER_KEY
JOIN CWD_USER c
ON b.USERNAME = c.USER_NAME
WHERE c.ACTIVE = 'F';

答案 2 :(得分:0)

您可以在下面尝试

DELETE FROM CONTENT_PERM
WHERE USERNAME IN (SELECT USER_KEY FROM user_mapping WHERE USERNAME IN (SELECT USER_NAME
from CWD_USER where ACTIVE = 'F'));