Skip to content

Commit 650118a

Browse files
committed
AMZN - 175
1 parent 5d26695 commit 650118a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Problem: 175. Combine Two Tables
2+
3+
Table: Person
4+
5+
+-------------+---------+
6+
| Column Name | Type |
7+
+-------------+---------+
8+
| PersonId | int |
9+
| FirstName | varchar |
10+
| LastName | varchar |
11+
+-------------+---------+
12+
PersonId is the primary key column for this table.
13+
Table: Address
14+
15+
+-------------+---------+
16+
| Column Name | Type |
17+
+-------------+---------+
18+
| AddressId | int |
19+
| PersonId | int |
20+
| City | varchar |
21+
| State | varchar |
22+
+-------------+---------+
23+
AddressId is the primary key column for this table.
24+
25+
Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people: FirstName, LastName, City, State
26+
27+
--------------------------------------------------------------------------------------------------------------------------------------
28+
Solution 1:
29+
30+
SELECT p.FirstName, p.LastName, a.City, a.State FROM Person p
31+
LEFT JOIN Address AS a ON p.PersonId = a.PersonId;
32+
33+
--------------------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)