
Problem

Example

Thinking
Output์ ํ์ธํ๋ฉด person table์ ์๋ ํ์๋ค์ ๋์ดํ๊ณ ๊ทธ ํ์์ ํด๋นํ๋ (personId๊ฐ ๋์ผํ) city, state ์ ๋ณด๋ฅผ ๊ฐ์ ธ์์ ํ ์ด๋ธ์ ์์ฑ์์ผฐ๋ค.
Address ์ ๋ณด๊ฐ ์๋ ํ์์ผ ๊ฒฝ์ฐ์๋ Null๋ก ํ์ ํด์ฃผ์๋ค.
ํ ์ด๋ธ์ด 2๊ฐ ์์ผ๋ join์ ํด์ค ๊ฒ์ด๋ฉฐ, ์กฐ์ธ ๊ธฐ์ค์ผ๋ก ์ผ์ชฝ(Person table) ์ ๋ณด๋ฅผ ๋ชจ๋ ๊ฐ์ ธ์ฌ ๊ฒ์ด๊ธฐ์ LEFT JOIN์ ์ฌ์ฉํด๋ณด์.
Solve
์ ์ถ ๋ต์
select p.firstName, p.lastName, a.city, a.state
from Person p left join Address a
on p.personId = a.personId

https://leetcode.com/problems/combine-two-tables/
Combine Two Tables - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
'๐ป leetcode > database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode] Database | 627. Swap Salary (0) | 2022.01.05 |
---|---|
[LeetCode] Database | 196. Delete Duplicate Emails (0) | 2022.01.03 |
[LeetCode] Database | 183. Customers Who Never Order (0) | 2022.01.02 |
[LeetCode] Database | 182. Duplicate Emails (0) | 2022.01.02 |
[LeetCode] Database | 181. Employees Earning More Than Their Manager (1) | 2022.01.02 |