JOIN과 UNION의 차이

Web Development assistant·2021년 11월 8일
0

# SQL

목록 보기
3/28

join과 union은 두 개 이상의 테이블을 합치는데 사용하는데
결과물은 다르게 표시된다.




join을 사용했을 경우

select * from authorities a join (select username, password from users) b on a.username = b.username;

a.username b.username 이 일치하는 행들을 수평결합한다.




union을사용했을 경우

select * from authorities union allselect username, password from users;

수직결합한다. (컬럼수를 맞춰 줘야함)

서로 다른 테이블을 합쳐 날짜순으로 정렬해야했을 떄 union all(중복제거 x) 을 사용했다.

0개의 댓글