where 子句中的多个列
multiple columns together in where clause
我有一个 table 订阅如下
订阅
user user_id cve_id vulnerability_id
------- ---------- ------------- -------------------
kumar 17 CVE-2016-3987 74
rajesh 16 CVE-2016-3987 74
我还有一个 table 如下所示
APP_USER_ID VULNERABILITY_ID STATUS
-------------- ------------------- ---------
16 74 assigned
我想检索目前尚未分配给用户的所有订阅。我尝试了以下查询
select * from subscription where user_id not in (select APP_USER_ID from app_user_subscription )
但是如果用户匹配,它会跳过所有订阅。我明白为什么会这样。因为我简单的只提到了user_id
。我想根据 user_id
和 cve_id
跳过。我需要如何更新我的查询?
通过在表上使用 LEFT OUTER JOIN
将返回所有行,您可以通过使用 WHERE
子句
返回具有空值的行来过滤未分配的行
SELECT a.* FROM user u
LEFT OUTER JOIN APP_USER_ID a on a.APP_USER_ID = u.user_id
WHERE u.user_id IS NULL
select * from subscription where (user_id,cve_id) not in (select APP_USER_ID,<corresponding column for cve_id> from app_user_subscription )
我有一个 table 订阅如下
订阅
user user_id cve_id vulnerability_id
------- ---------- ------------- -------------------
kumar 17 CVE-2016-3987 74
rajesh 16 CVE-2016-3987 74
我还有一个 table 如下所示
APP_USER_ID VULNERABILITY_ID STATUS
-------------- ------------------- ---------
16 74 assigned
我想检索目前尚未分配给用户的所有订阅。我尝试了以下查询
select * from subscription where user_id not in (select APP_USER_ID from app_user_subscription )
但是如果用户匹配,它会跳过所有订阅。我明白为什么会这样。因为我简单的只提到了user_id
。我想根据 user_id
和 cve_id
跳过。我需要如何更新我的查询?
通过在表上使用 LEFT OUTER JOIN
将返回所有行,您可以通过使用 WHERE
子句
SELECT a.* FROM user u
LEFT OUTER JOIN APP_USER_ID a on a.APP_USER_ID = u.user_id
WHERE u.user_id IS NULL
select * from subscription where (user_id,cve_id) not in (select APP_USER_ID,<corresponding column for cve_id> from app_user_subscription )