
안녕하세요. [퀴즈] Join 연습5 문제를 풀다가 궁금한 게 있어서요.
이 문제의 정답은 아래와 같은데요.
select c1.title, c2.week, count(*) as cnt from courses c1
inner join checkins c2 on c1.course_id = c2.course_id
inner join orders o on c2.user_id = o.user_id
where o.created_at >= '2020-08-01'
group by c1.title, c2.week
order by c1.title, c2.week
두 번째 inner join 시에 왜 user_id로 연결해야 하나요?
courses, checkins, orders 테이블 모두 course_id가 있으니까,
전부 course_id로 연결해도 되지 않을까 해서 아래와 같이 적었는데요.
select c1.title, c2.week, count(*) from courses c1
inner join checkins c2 on c1.course_id = c2.course_id
inner join orders o on c2.course_id = o.course_id
where o.created_at >= '2020-08-01'
group by c1.title, c2.week
order by c1.title, c2.week
결과값이 다르게 나오네요ㅠㅠ
궁금합니다!
