2016-11-02 8 views
2

이 두 테이블을 결합 표 1 :오라클 : 다른 열

col_1 col_2 date_1 
----- ----- ------ 
1  3  2016 
2  4  2015 

그리고 이것은 표 2 : 내가 원하는

col_3 col_4 date_2 
----- ----- ------ 
5  8  2014 
6  9  2012 

이 같은 결과 :

col_1 col_2 col_3 col_4 date_1 date_2 
----- ----- ----- ----- ------ ------ 
1  3  NULL NULL 2016 NULL 
2  4  NULL NULL 2015 NULL 
NULL NULL 5  8  NULL 2014 
NULL NULL 6  9  NULL 2012 

어떤 해결책?

+0

모든 성공하지 않고, 조합 또는 조합 결합합니다. –

답변

6

다른 열로 Union AllNull 사용 :

SELECT col_1, col_2, NULL as col_3, NULL as col_4, 
     date_1, NULL as date_2 
FROM table_1 

Union All 

SELECT NULL, NULL, col_3, col_4, NULL, date_2 
FROM table_2 
2

사용 union all : 가입 사용

select col_1, col_2, NULL as col_3, NULL as col_4, date_1, NULL as date_2 
from table1 
union all 
select NULL, NULL, col_3, col_4, NULL, date_2 
from table2; 
0

:

select t1.col_1,t1.col_2,t2.col_3,t2.col_4,t1.date_1,t2.date_2 
from t1 
full join t2 
on t1.col_1=t2.col_3 
order by t1.col_1;