Leetcode

[MySQL] 3. 175. Combine Two Tables [LeetCode Easy]

치킨먹고싶어요 2022. 5. 25. 17:56

https://leetcode.com/problems/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.
cs

firstName , lastName, city, state를 출력하라,
그러나 Address table에 personId가 없으면, null을 리턴하라는 내용입니다.

Person table과 Address table이 나오며 Null이 나오니, 두 테이블을 합쳐주며 없을 경우 null을 리턴하는
Join을 쉽게 생각할 수 있습니다.

SELECT P.firstName , P.lastName, A.city, A.state
FROM Person AS P
LEFT JOIN Address AS A ON P.personId = A.personId
 
cs

 

통과되었습니다.