Problem Description
Write a 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. ### Example **Person Table:** | personId | lastName | firstName | | :--- | :--- | :--- | | 1 | Wang | Allen | | 2 | Alice | Bob | **Address Table:** | addressId | personId | city | state | | :--- | :--- | :--- | :--- | | 1 | 2 | New York City | New York | **Expected Output:** | firstName | lastName | city | state | | :--- | :--- | :--- | :--- | | Allen | Wang | NULL | NULL | | Bob | Alice | New York City | New York |
Database Schema
undefined
Sample SQL Solution
-- Write your SQL query to combine Person and Address
SELECT
p.firstName,
p.lastName,
a.city,
a.state
FROM Person p
LEFT JOIN Address a ON p.personId = a.personId;