Practice Combine Two Tables
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Tables: Person(personId INT, lastName VARCHAR, firstName VARCHAR); Address(addressId INT, personId INT, city VARCHAR, state VARCHAR). Person.personId and Address.addressId are unique keys; Address.personId identifies the person. Report firstName, lastName, city and state for every person, keeping people without an address and using null for their city and state. Output order does not matter. A left join from Person preserves the unmatched people.
Source: Combine Two Tables on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Person table: +----------+----------+-----------+ | personId | lastName | firstName | +----------+----------+-----------+ | 1 | Wang | Allen | | 2 | Alice | Bob | +----------+----------+-----------+ Address table: +-----------+----------+---------------+------------+ | addressId | personId | city | state | +-----------+----------+---------------+------------+ | 1 | 2 | New York City | New York | | 2 | 3 | Leetcode | California | +-----------+----------+---------------+------------+
+-----------+----------+---------------+----------+ | firstName | lastName | city | state | +-----------+----------+---------------+----------+ | Allen | Wang | Null | Null | | Bob | Alice | New York City | New York | +-----------+----------+---------------+----------+
Related LeetCode Problems
Practice more problems similar to Combine Two Tables.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.