# Combine Two Tables Problem

## Description

LeetCode Problem 175.

Table: Person

``````1
2
3
4
5
6
7
8
+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| PersonId    | int     |
| FirstName   | varchar |
| LastName    | varchar |
+-------------+---------+
PersonId is the primary key column for this table.
``````

``````1
2
3
4
5
6
7
8
9
+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| AddressId   | int     |
| PersonId    | int     |
| City        | varchar |
| State       | varchar |
+-------------+---------+
AddressId is the primary key column for this table.
``````

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:

``````1
FirstName, LastName, City, State
``````

## MySQL Solution

We can join the two tables to get the address information of a person. Considering there might not be an address information for every person, we should use outer join instead of the default inner join.

``````1
2
3
from Person
left join Address on Person.PersonId = Address.PersonId;
``````