-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d60d73
commit 8527279
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<h2><a href="https://leetcode.com/problems/combine-two-tables/">175. Combine Two Tables</a></h2><h3>Easy</h3><hr><div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div><div><p>Table: <code>Person</code></p> | ||
|
||
<pre>+-------------+---------+ | ||
| Column Name | Type | | ||
+-------------+---------+ | ||
| personId | int | | ||
| lastName | varchar | | ||
| firstName | varchar | | ||
+-------------+---------+ | ||
personId is the primary key (column with unique values) for this table. | ||
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 | | ||
+-------------+---------+ | ||
addressId is the primary key (column with unique values) for this table. | ||
Each row of this table contains information about the city and state of one person with ID = PersonId. | ||
</pre> | ||
|
||
<p> </p> | ||
|
||
<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> | ||
|
||
<p>Return the result table in <strong>any order</strong>.</p> | ||
|
||
<p>The result format is in the following example.</p> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<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> | ||
</div> |