-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0175-Combine_Two_Tables.sql
More file actions
54 lines (53 loc) · 1.64 KB
/
0175-Combine_Two_Tables.sql
File metadata and controls
54 lines (53 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*******************************************************************************
* 0175-Combine_Two_Tables.sql
* Billy.Ljm
* 19 July 2025
*
* =======
* Problem
* =======
* https://leetcode.com/problems/combine-two-tables/
*
* Table: Person
* +-------------+---------+
* | 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.
*
*
* Table: Address
* +-------------+---------+
* | 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.
*
*
* 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.
*
* ===========
* My Approach
* ===========
* Simply left join the Address table to the Person table and select the desired
* columns.
******************************************************************************/
SELECT Person.firstname, Person.lastname, Address.city, Address.state
FROM Person
LEFT JOIN Address
ON Person.personId = Address.personId