2013-03-08 78 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) 
相关问题