[SQL] 두 테이블의 값 비교, 한쪽에 없는 것 추출방법은? > MySQL

본문 바로가기
사이트 내 전체검색

MySQL

[SQL] 두 테이블의 값 비교, 한쪽에 없는 것 추출방법은?

페이지 정보

profile_image
작성자 최고관리자
댓글 0건 조회 68회 작성일 20-01-03 17:12

본문

create table tableA ( EMPNO int)

create table tableB ( EMPNO int)


insert into tableA values (1)

insert into tableA values (2)

insert into tableA values (3)

insert into tableA values (4)

insert into tableA values (5)


insert into tableB values (1)

insert into tableB values (2)

insert into tableB values (3)

insert into tableB values (4)

insert into tableB values (7)


 -- A 테이블에만 존재하는 항목

select A.EMPNO

from tableA A left outer join tableB B on A.EMPNO=B.EMPNO

where B.EMPNO is null


-- B 테이블에만 존재하는 항목

select B.EMPNO

from tableA A right outer join tableB B on A.EMPNO=B.EMPNO

where A.EMPNO is null


-- A, B 테이블에 서로 없는것을 동시에

select A.EMPNO

from tableA A left outer join tableB B on A.EMPNO=B.EMPNO

where B.EMPNO is null


UNION ALL


select B.EMPNO

from tableA A right outer join tableB B on A.EMPNO=B.EMPNO

where A.EMPNO is null


 -- 다른 방법으로  (A, B 테이블에 서로 없는것을 동시에)

select isnull(A.EMPNO,B.EMPNO)

from tableA A full outer join tableB B on A.EMPNO=B.EMPNO

where B.EMPNO is null or A.EMPNO is null

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

접속자집계

오늘
8
어제
9
최대
70
전체
2,979
Copyright © OHPR All rights reserved.