문제 175. Combine Two Tables
Write an SQL query to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead.
person 테이블을 기준으로 이름, 성, 도시, 주를 반환하는 쿼리문을 작성하는 문제다.
SELECT firstName, lastName, city, state
FROM person LEFT JOIN address
ON person.personID = address.personID;
💡
LEFT JOIN
을 사용했다. ON
다음 조인조건을 쓸 때 두 조건을 ==
으로 비교했기 때문이다!!! 어제 파이썬을 하며 헷갈렸나. 다시 한번 집고 넘어가자.=
, <>
, <
, <=
, >
, ≥
BETWEEN
a AND
b (=a, b 포함)IN
, NOT IN
LIKE
, NOT LIKE
IS NULL
, IS NOT NULL
AND
, OR
, NOT