KEEP GOING
[MySQL] LeetCode : Combine Two Tables Solution 본문
반응형
    
    
    
  

https://leetcode.com/problems/combine-two-tables/submissions/
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
Table: Person
+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| personId    | int     |
| lastName    | varchar |
| firstName   | varchar |
+-------------+---------+
personId is the primary key column for this table.
This table contains information about the ID of some persons and their first and last names.
Table: Address
+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| addressId   | int     |
| personId    | int     |
| city        | varchar |
| state       | varchar |
+-------------+---------+
addressId is the primary key column for this table.
Each row of this table contains information about the city and state of one person with ID = PersonId.
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.
Return the result table in any order.
1. 코드 구현
# left join 사용 
SELECT p.firstName, p.lastName, a.city, a.state
FROM Person p 
LEFT JOIN Address a ON p.personId = a.personId;반응형
    
    
    
  'code review > sql' 카테고리의 다른 글
| [MySQL] HackerRank : Weather Observation Station 11 Solution (0) | 2021.12.21 | 
|---|---|
| [MySQL] HackerRank : New Companies Solution (0) | 2021.12.20 | 
| [MySQL] 기출 예제 정리 (0) | 2021.12.02 | 
| [MySQL] JOIN 정리 (INNER JOIN, LEFT/RIGHT JOIN, OUTER JOIN) (0) | 2021.12.02 | 
| [MySQL] 프로그래머스 코딩 테스트 - 동명 동물 수 찾기 (GROUP BY 사용) (0) | 2021.12.02 | 
			  Comments