diff --git a/src/main/java/g0101_0200/s0175_combine_two_tables/readme.md b/src/main/java/g0101_0200/s0175_combine_two_tables/readme.md index f335cc6f1..be56bdce2 100644 --- a/src/main/java/g0101_0200/s0175_combine_two_tables/readme.md +++ b/src/main/java/g0101_0200/s0175_combine_two_tables/readme.md @@ -2,8 +2,6 @@ Easy -SQL Schema - Table: `Person` +-------------+---------+ @@ -13,8 +11,7 @@ Table: `Person` | lastName | varchar | | firstName | varchar | +-------------+---------+ - - personId is the primary key column for this table. + 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. Table: `Address` @@ -27,19 +24,18 @@ Table: `Address` | city | varchar | | state | varchar | +-------------+---------+ - - addressId is the primary key column for this table. + 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. -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. +Write a solution 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**. -The query result format is in the following example. +The result format is in the following example. **Example 1:** -**Input:** +**Input:** Person table: +----------+----------+-----------+ @@ -48,7 +44,7 @@ The query result format is in the following example. | 1 | Wang | Allen | | 2 | Alice | Bob | +----------+----------+-----------+ - + Address table: +-----------+----------+---------------+------------+ | addressId | personId | city | state | @@ -68,4 +64,4 @@ The query result format is in the following example. **Explanation:** -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. +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. \ No newline at end of file diff --git a/src/main/java/g0101_0200/s0175_combine_two_tables/script.sql b/src/main/java/g0101_0200/s0175_combine_two_tables/script.sql index ab0dd6a27..51c2ec9d9 100644 --- a/src/main/java/g0101_0200/s0175_combine_two_tables/script.sql +++ b/src/main/java/g0101_0200/s0175_combine_two_tables/script.sql @@ -1,12 +1,5 @@ # Write your MySQL query statement below -# #Easy #Database #SQL_I_Day_5_Union #2022_06_26_Time_491_ms_(32.30%)_Space_0B_(100.00%) -SELECT - FirstName, - LastName, - City, - State -FROM - Person -LEFT JOIN - Address -USING (PersonId); +# #Easy #Database #SQL_I_Day_5_Union #2026_11_30_Time_336_ms_(96.67%)_Space_0B_(100.00%) +SELECT p.firstName , p.lastName , a.city , a.state +FROM Person p left join Address a +on p.personId = a.personId;