假設表T1
包含的值'A','B','C'
和表T2
包含的值'A','B','D'
您可以查詢
select 'T1' as source, col from t1
union all
select 'T2' as source, col from t2
union all
select 'join T1,T2' as source, t1.col from t1 inner join t2
on t1.col= t2.col
order by 1,2
;
得到
SOURCE COL
---------- -----
T1 A
T1 B
T1 C
T2 A
T2 B
T2 D
join T1,T2 A
join T1,T2 B
第一列標識源:單個查詢或加入
或者,我會更喜歡你可能會使用FULL OUTER相同的信息(更壓縮)JOIN
with fj as (
select t1.col t1_col, t2.col t2_col
from t1 full outer join t2
on t1.col= t2.col
)
select
case when t1_col is not null and t2_col is not null then 'both'
when t1_col is not null then 'T1 only'
when t2_col is not null then 'T2 only' end as source,
nvl(t1_col, t2_col) col
from fj
order by 1,2
。
SOURCE COL
------- ----------
T1 only C
T2 only D
both A
both B
你是說你想要打印的select語句的結果以及隨後的內部連接的結果打印? –
是的,我需要他們都打印和兩個表內部由類似列連接 – TrickyDBA
請提供兩個表的示例數據,以及預期結果的示例。否則,它不是很清楚。 – sstan