2013-05-22 55 views

回答

4
select field from tab1 
union all 
select field from tab2 

minus 

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

OR :)

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

+0

最後的查詢不適用於這種情況。它將只顯示兩個表中的常見值 – Thiyagu

+0

我已經添加了一個sqlfiddle來顯示否則。它顯示非常見記錄。 –

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

它會工作,但在運營商將影響性能。 – Thiyagu