## [LeetCode]Combine Two Tables 作者是 在线疯狂 发布于 2015年1月12日 在 LeetCode.

LeetCode在原有的算法（Algorithm）题目分类基础之上，推出了全新的数据库（Database）题目分类，旨在帮助开发者提高数据库的开发技能。

Database分类下的第一题叫做Combine Two Tables，非常简单，大家可以拿来练手。只需将SQL语句填写在答题区即可。

## 题目描述：

Table: Person

```+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| PersonId    | int     |
| FirstName   | varchar |
| LastName    | varchar |
+-------------+---------+
```

PersonId is the primary key column for this table.

```+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| 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:

FirstName, LastName, City, State

## SQL语句：

``````# Write your MySQL query statement below
SELECT p.FirstName, p.LastName, a.City, a.State
FROM Person p LEFT OUTER JOIN Address a USING (PersonId);
``````

Pingbacks已关闭。