-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path175. Combine Two Tables.sql
More file actions
53 lines (44 loc) · 1.26 KB
/
175. Combine Two Tables.sql
File metadata and controls
53 lines (44 loc) · 1.26 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
/*
Question 175. Combine Two Tables
Link: https://leetcode.com/problems/combine-two-tables/description/
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.
*/
SELECT
Person.firstName,
Person.lastName,
Address.city,
Address.state
FROM
Person
LEFT JOIN
Address
ON
Person.personId = Address.personId