LeetCode 175. Combine Two Tables SQL Solution
Problem
LeetCode SQL Problem
- Combine Two Tables
Solution
We can join the two tables to get the address information of a person. We use left outer join to ensure each person is showing up in the result even though he/she might not have an associated address record.
- MySQL
- TSQL
SELECT p.firstName,
p.lastName,
a.city,
a.STATE
FROM Person p
LEFT JOIN Address a
ON p.personId = a.personId;
SELECT p.firstName,
p.lastName,
a.city,
a.STATE
FROM Person p
LEFT JOIN Address a
ON p.personId = a.personId;