๐ป leetcode/database
[LeetCode] Database | 175. Combine Two Tables
๋ฐ์ฟ๋ฆฌ
2021. 12. 29. 19:14
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