1

我有两个具有以下值的表。

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

输出应如下所示:

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

2 回答 2

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

但是,最好的(性能:)):

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;

请参阅此处对上述查询的测试。

于 2013-05-22T13:59:40.373 回答
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)
于 2013-05-22T13:34:04.417 回答