码疯窝

LeetCode 每日一题 — Combine Two Tables

2015/01/13 10:43:30    分类: 日志连载    0人评论 次浏览

Table: Person

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

PersonId is the primary key column for this table.

Table: Address

+-------------+---------+
| 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:

FirstName, LastName, City, State

算法分析: 今天很意外的发现Leetcode上面竟然更新了4道MYSQL的题目, 但是点进去发现太侮辱人了. 这种题目放上面有意思么, 是要考INNER JOIN, LEFT JOIN, RIGHT JOIN 这种基础知识么?

SELECT FirstName, LastName, City, State
FROM Person p
LEFT JOIN Address a
ON p.PersonId = a.PersonId
继续查看有关 日志连载的文章

0个访客评论