동뀨의 story
3주차 개발일지 본문
Join이란?
두 테이블의 공통된 정보 (key값)를 기준으로 테이블 연결해서 한 테이블로 보는 것
inner join: 교집합
Left join: A의 기준으로 A∪B but A의 속하지 않는 값은 Null로 표시 한다.

select * from enrolleds e
inner join courses c
on e.course_id = c.course_id;
위 커리가 실행 되는 순서: from ~> Join ~> select
Union: 결과물 합치기
Select을 두 번 할게 아니라, 한번에 모아서 보고싶은 경우, 사용한다.
ex)
(
select '7월' as month, c.title, c2.week, count(*) as cnt from checkins c2
inner join courses c on c2.course_id = c.course_id
inner join orders o on o.user_id = c2.user_id
where o.created_at < '2020-08-01'
group by c2.course_id, c2.week
order by c2.course_id, c2.week
)
union all
(
select '8월' as month, c.title, c2.week, count(*) as cnt from checkins c2
inner join courses c on c2.course_id = c.course_id
inner join orders o on o.user_id = c2.user_id
where o.created_at > '2020-08-01'
group by c2.course_id, c2.week
order by c2.course_id, c2.week
)
Comments