1. 문제
Table: Person
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| PersonId | int |
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
PersonId is the primary key column for this table.
Table: Address
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| AddressId | int |
| PersonId | int |
| City | varchar |
| State | varchar |
+-------------+---------+
AddressId is the primary key column for this table.
Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:
FirstName, LastName, City, State
2. 답
SELECT FirstName, LastName, City, State
FROM person
LEFT JOIN address ON person.personid = address.personid
3. KEY POINT
- LEFT JOIN : 모든 사람의 주소 정보가 없을 수 있으므로 INNER JOIN이 아닌 LEFT JOIN을 사용
leetcode.com/problems/combine-two-tables/
'MySQL > 문제풀이' 카테고리의 다른 글
[HackerRank] 여러 개의 INNER JOIN : New Companies (0) | 2021.03.22 |
---|---|
[HackerRank] Japan Population / Weather Observation Station 2 / Weather Observation Station 18 (0) | 2021.03.22 |
[LeetCode] 182. Duplicate Emails (0) | 2021.03.22 |
[LeetCode] 620. Not Boring Movies (0) | 2021.03.22 |
[LeetCode] 595. Big Countries (0) | 2021.03.22 |
댓글