我有两张桌子如下。我正在使用Oracle 10g
TableA
---------
id Name
--- ----
1 abc
2 def
3 xxx
4 yyy
TableB
---------
id Name
--- ----
1 abc
2 def
TableC
---------
id Name
--- ----
1 abc
2 def
现在我需要获取ID from TableA which are not there in TableB and TableC
。如何在不使用NOT IN子句的情况下执行此操作?
请帮助我!
谢谢!
答案 0 :(得分:2)
请尝试:
SELECT
a.ID,
a.NAME
FROM
TABLEA a LEFT JOIN TABLEB b ON a.ID=b.ID
LEFT JOIN TABLEC c ON a.ID=c.ID
WHERE
b.ID IS NULL AND
c.ID IS NULL;
答案 1 :(得分:1)
select * from TableA
minus
select * from TableB
编辑:
同时不在B和C中:
select * from TableA
minus (
select * from TableB
intersect
select * from TableC
)
不在B或C中:
select * from TableA
minus
select * from TableB
minus
select * from TableC
答案 2 :(得分:0)
select a.id
from tableA a,tableB b,tableC c
where a.id != b.id and a.id!=c.id
这样好吗?
答案 3 :(得分:0)
select * from TableA
minus
(select * from TableB
union
select * from TableC)