【发布时间】:2013-04-18 01:49:07
【问题描述】:
我有table A, B and C
我想返回表 A 中不存在于表 B 中且该列表中不存在于表 C 中的所有条目。
select * from table_A as a
where not exists (select 1 from table_B as b
where a.id = b.id)
这给了我 A 中不在 B 中的条目的第一个结果。但现在我只想要该结果中也不在 C 中的条目。
我尝试了以下口味:
select * from table_A as a
where not exists (select 1 from table_B as b
where a.id = b.id)
AND
where not exists (select 1 from table_C as c
where a.id = c.id)
但这不是正确的逻辑。如果有办法存储第一个查询的结果,然后从表 C 中不存在的结果中选择 *。但我不知道该怎么做。感谢您的帮助。
【问题讨论】:
-
您使用的是什么数据库系统?
标签: sql sql-server correlated-subquery