2013-03-08 76 views
0

我有兩個表如下。我正在使用Oracle 10g從Table1中獲取表中缺少table2 oracle的行嗎?

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 

現在我需要獲得ids from TableA which are not there in TableB and TableC。我怎樣才能做到這一點,而不使用NOT IN子句?

請幫幫我!

謝謝!

+0

wt如果你加入id不等於條件的兩個表並獲得獨特的ID? – 2013-03-08 10:55:39

回答

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; 
+0

我編輯了我的問題。 Plz幫助我。 – user1016403 2013-03-08 11:08:04

+0

請檢查編輯答案。 – TechDo 2013-03-08 11:14:45

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 
+0

我編輯了我的問題。 Plz幫助我! – user1016403 2013-03-08 11:08:35

+0

@ user1016403 - ok – 2013-03-08 11:18:12

0
select a.id 
from tableA a,tableB b,tableC c 
where a.id != b.id and a.id!=c.id 

這是罰款?

0
select * from TableA 
minus 
(select * from TableB 
union 
select * from TableC) 
相關問題