查找oracle中两个表中不常见的行

时间:2013-05-22 13:30:12

标签: oracle

我有两个包含以下值的表格。

tab1              tab2
----              ----
A                   A
B                   E
C                   F
D                   G

输出应如下:

O/P
---
B
C
D
E
F
G

2 个答案:

答案 0 :(得分:4)

select field from tab1
union all
select field from tab2

minus

(select field from tab1
 intersect
 select field from tab2
);

或:)

select field from tab1
minus
select field from tab2

union all

select field from tab2
minus
select field from tab1

但是,BEST(性能:)):

select distinct nvl(a.field, b.field) as field
from tab1 a
full join tab2 b on (a.field=b.field)
where a.field is null or b.field is null;

请在此处查看test以查询上述内容。

答案 1 :(得分:1)

select field from tab1 where field not in (select field from tab2) 
union 
select field from tab2 where field not in (select field from tab1)