코딩배움일지/DataBase

DB 6일차 3-1(union)

karatejin 2022. 12. 14. 11:53

다른 테이블 합칠때 테이블의 형태가 같아야 한다.

순서도 같아야 한다.

 

select
	name
from
	user_dtl    
union /* union 중복 제거 해서 보여줌  unionall 중복제거 안하고 보여줌*/
select
	name
from
	score_mst;

 

 

select /*순서 일치*/ 
	name,
    email
from
	user_dtl    
union /* union 중복 제거 해서 보여줌  unionall 중복제거 안하고 보여줌*/
select
	name,
    null as email
from
	score_mst;

 

 

select /*순서 일치*/ 
	name,
    email,
    0 as score
from
	user_dtl    
union /* union 중복 제거 해서 보여줌  unionall 중복제거 안하고 보여줌*/
select
	name,
    null as email,
    score
from
	score_mst;

 

select /*순서 일치*/ 
	name,
    email,
    0 as score
from
	user_dtl    
union /* union 중복 제거 해서 보여줌  unionall 중복제거 안하고 보여줌*/
select
	name,
    null as email,
    score
from
	score_mst    
where
	score > 80 ;

 

 

select /*순서 일치*/ 
	name,
    email,
    0 as score
from
	user_dtl
where
	name = '김준일'

union /* union 중복 제거 해서 보여줌  unionall 중복제거 안하고 보여줌*/
select
	name,
    null as email,
    score
from
	score_mst    
where
	score > 80 ;