두 개 이상의 테이블을 결합하는 것
select column1, column2,...
from tableA
inner join tableB
on tableA.column = table.column
where condition;
select column1, column2,...
from tableA
left join tableB
on tableA.column = table.column
where condition;
select column1, column2,...
from tableA
right join tableB
on tableA.column = table.column
where condition;
select column1, column2,...
from tableA
full outer join tableB
on tableA.column = table.column
where condition;
🚨 MYSQL 에서는 FULL OUTER JOIN을 지원하지 않으므로 사용불가!🚨
( LEFT JOIN 과 RIGHT JOIN을 UNION으로 연결해 아래와 같이 해결가능 )
select column1, column2,...
from tableA
left join tableB
on tableA.column = table.column
where condition
union
```sql
select column1, column2,...
from tableA
right join tableB
on tableA.column = table.column
where condition;
select column1, column2,...
from tableA, tableB
where condition;
✏️예시
- celeb 테이블의 연예인 중, snl_show 에 host 로 출연했고 소속사가 안테나인 사람의 이름과 직업을 찾아라
select celeb.name, celeb.job_title from celeb, snl_show where celeb.name = snl_show.host and celeb.agency = '안테나';
or
select name, job_title from celeb, snl_show where name = host and agency = '안테나';
🚨유의사항🚨
동일한 컬럼명이 존재하는 경우에만 테이블명을 암시해도 된다.
BUT 쿼리 가독성을 위해 컬럼명을 명시하는 편이 좋음.