728x90
문제
Column Name | Type |
personId | int |
lastName | varchar |
firstName | varchar |
[Table : Person]
personId is the primary key (column with unique values) for this table.
This table contains information about the ID of some persons and their first and last names.
Column Name | Type |
addressId | int |
personId | int |
city | varchar |
state | varchar |
[Table : Address]
addressId is the primary key (column with unique values) for this table.
Each row of this table contains information about the city and state of one person with ID = PersonId.
Write a solution 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 테이블의 각각 사람의 first name, last name, city, state 를 출력해라.
정보가 없다면 null 로 대신 출력해라.
풀이
SELECT a.firstName, a.lastName, b.city, b.state
FROM Person a
LEFT OUTER JOIN Address b ON a.personId = b.personId
출력결과
firstName | lastName | city | state |
Allen | Wang | null | null |
Bob | Alice | New York City | New York |
300x250
'Data & BI > SQL Coding Test' 카테고리의 다른 글
[LeetCode](중급) 176. Second Highest Salary (0) | 2025.05.16 |
---|---|
[LeetCode](초급) 183. Customers Who Never Order (1) | 2025.05.16 |
[LeetCode](초급) 182. Duplicate Emails (0) | 2025.05.16 |