Practice > SQL > Basic Join > African Cities

Problem

Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is 'Africa'.
Note: CITY.CountryCode and COUNTRY.Code are matching key columns.
문제링크

Answer

SELECT city.name
FROM city
     INNER JOIN country ON city.countrycode = country.code
WHERE country.continent = 'Africa'
-- SQP Visualizer → INNER JOIN 은 교집합
-- INNER JOIN은 양쪽 모두에 있는 테이블만 출력하는 것
-- INNER JOIN 여러개 쓸 수 있다
-- 서로 JOIN KEY 로 쓸 수 없는 경우인데, 이름이 똑같은 경우가 있다
-- (테이블이 너무 많아서) 반대로 조인키로 사용해야하는데 이름이 다른 경우도 존재한다. → ERD를 알아야함.

0개의 댓글