2022-03-27 20:56:26 +08:00
< p > Table: < code > Person< / code > < / p >
< pre >
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| personId | int |
| lastName | varchar |
| firstName | varchar |
+-------------+---------+
2023-12-09 18:42:21 +08:00
personId is the primary key (column with unique values) for this table.
2022-03-27 20:56:26 +08:00
This table contains information about the ID of some persons and their first and last names.
< / pre >
< p > < / p >
< p > Table: < code > Address< / code > < / p >
< pre >
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| addressId | int |
| personId | int |
| city | varchar |
| state | varchar |
+-------------+---------+
2023-12-09 18:42:21 +08:00
addressId is the primary key (column with unique values) for this table.
2022-03-27 20:56:26 +08:00
Each row of this table contains information about the city and state of one person with ID = PersonId.
< / pre >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > Write a solution to report the first name, last name, city, and state of each person in the < code > Person< / code > table. If the address of a < code > personId< / code > is not present in the < code > Address< / code > table, report < code > null< / code > instead.< / p >
2022-03-27 20:56:26 +08:00
< p > Return the result table in < strong > any order< / strong > .< / p >
2023-12-09 18:42:21 +08:00
< p > The result format is in the following example.< / p >
2022-03-27 20:56:26 +08:00
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 20:56:26 +08:00
< pre >
< strong > Input:< / strong >
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 |
+-----------+----------+---------------+------------+
< strong > Output:< / strong >
+-----------+----------+---------------+----------+
| firstName | lastName | city | state |
+-----------+----------+---------------+----------+
| Allen | Wang | Null | Null |
| Bob | Alice | New York City | New York |
+-----------+----------+---------------+----------+
< strong > Explanation:< / strong >
There is no address in the address table for the personId = 1 so we return null in their city and state.
addressId = 1 contains information about the address of personId = 2.
< / pre >