select column1, column2, ...
from table A
INNER JOIN table B
ON table A.column = table B.column (기준! table A의 이런 column과 table B의 저런 column이 같을 경우 join한다)
where 조건
예제) snl_show에 호스트로 출연한 celeb을 기준으로 celeb테이블과 snl_show 테이블을 INNER JOIN
SNL에 출연한 적이 있는 연예인만 나옴.
Select celeb. id, celeb. name, snl_show.id, snl_show.host
From celeb
INNER JOIN snl_show
ON celeb.name = snl_show.host;

select column1, column2, ...
from table A (table A가 LEFT TABLE이 된다)
FULL OUTER JOIN table B (table B가 RIGHT TABLE이 된다)
ON table A.column.column = table B.column
where 조건;
SELECT column1, column2, ...
from table A (table A가 LEFT TABLE이 된다)
LEFT JOIN table B (table B가 RIGHT TABLE이 된다)
ON table A.column.column = table B.column
UNION(합치고 중복 제거)
SELECT column1, column2, ...
from table A (table A가 LEFT TABLE이 된다)
RIGHT JOIN table B (table B가 RIGHT TABLE이 된다)
ON table A.column.column = table B.column
WHERE 조건

select column1, column2, ...
from table A (table A가 LEFT TABLE이 된다)
LEFT JOIN table B (table B가 RIGHT TABLE이 된다)
ON table A.column.column = table B.column
where 조건;
예제) SNL에 출연한 사람과 출연하지 않은 CELEB 정보까지 나옴
NULL 표시는 SNL에 나온 적이 없는 celeb
Select celeb.id, celeb.name, snl.show.id, snl_show.host
From celeb
Left join snl_show
ON celeb.name = snl_show_host;

select column1, column2, ...
from table A (table A가 LEFT TABLE이 된다)
RIGHT JOIN table B (table B가 RIGHT TABLE이 된다)
ON table A.column.column = table B.column
where 조건;
예제) SNL에 출연한 celeb을 기준으로 celeb 테이블과 snl_show 테이블을 RIGHT JOIN
NULL로 표시되는 부분은 celeb에 없는 데이터 정보
Select celeb.id, celeb.name, snl.show.id, snl_show.host
From celeb
Left join snl_show
ON celeb.name = snl_show_host;

SELECT column1, column2, ...
FROM talbe A, table B (테이블이 여러 개가 될 수 있다)
where 조건
Select celeb.id, celeb.name, snl_show.id, snl_show.host
from celeb, snl_show
where celeb.name = snl_show.host;

celeb 테이블에서 소속사가 안테나인 사람은?
Select name, job_title from celeb where agency = '안테나';
celeb 테이블에서 snl에 출연한 사람은?
Select celeb.name, snl_show.host
from celeb, snl_show
where celeb.name = snl_show.host;
다 합치기
Select celeb.name, celeb.job_title
from celeb, snl_show
where celeb.name = snl_show.host AND celeb.agency = '안테나';

영화배우는 아니면서 YG 소속이거나 40세 이상이면서 YG 소속이 아닌 연예인의 이름, 나이, 직업, 소속사, 시즌, 에피소드 정보를 검색
celeb 테이블의 연예인 중 영화배우는 아니면서 YG 소속
Select * from celeb
Where NOT job_title LIKE '%영화배우%' AND agency = 'YG'
celeb 테이블의 연예인 중 40세 이상이면서 YG 소속이 아닌
Select * from celeb
Where age >= 40 AND NOT agency = 'YG'
celeb 테이블의 연예인 중 snl에 출연했고
select celeb.id, celeb.name, snl_show.host
from celeb, snl_show
where celeb.anme = snl_show.host
celeb 테이블 연예인 중 snl에 출연했고, 영화배우는 아니면서 YG 소속이거나
Select celeb.id, celeb.name, snl_show.host
from celeb, snl_show
where celeb.name = snl_show. host
AND NOT job_title LIKE '%영화배우%' AND agency = 'YG'
전부 합치기
Select celeb.name, celeb.age, celeb.job_title, celeb.agency, snl_show.season, snl_show.episode
From celeb, snl_show
Where celeb.name = snl_show.host
AND ((NOT job_title LIKE '%영화배우%' AND agency = 'YG')
OR (age >= 40 AND not agency = 'YG')


season, episode, name, job_title은 한쪽 테이블에만 존재하기 때문에 명시 안해도 되긴 한다.
소속사가 YG로 시작하고 뒤에 6글자로 끝나는 사람 중 작년 9월 15일 이후에 출연했던 사람은?
Select celeb.name, snl_show.season, snl_show.edpisode, snl_show.broadcast_date, celeb.agency
from celeb, snl_show
Where celeb.name = snl_show.host
AND (snl_show.episode IN (7. 9, 10) OR (celeb.agency LIKE 'YG__')
AND snl_show.broadcast_date > '2020-09-15';
