我有一个条目表A.
在表B中,我有两列带有A的条目ID(让我们称之为col1和col2)。如何获取A中的ID列表,这些ID不在B的这两列中。
我使用的查询是
select A.id from A where A.id not in (select distinct B.col1 from B) and A.id not in (select distinct B.col2 from B);
答案 0 :(得分:0)
SELECT ID
FROM A
WHERE ID NOT IN
(SELECT colA as ID From B
Union
Select colB as ID From B)
答案 1 :(得分:0)
由于你想要那些“不在B的这两列中的那些”,你想要那些不在col1中或者不在col2中或者不在col2中的那些,所以你必须将AND改为OR:< / p>
select A.id from A
where A.id not in (select distinct B.col1 from B)
or A.id not in (select distinct B.col2 from B);