描述
Table: Person
1 | +-------------+---------+ |
Table: Address
1 | +-------------+---------+ |
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 |
分析
题目要求是列出 Person 表里的所有人,不管这个人是否在 Address 表里存在,也就是说如果这个 PersonId 在 Person 表里是存在的,但在 Address 表里不存在的,那么也应该被列出来,只是地址信息为空而已。所以这是一个左外连接的问题,要包含 Person 表里的所有数据,尽管这个数据在 Address 表里不一定存在。
解决方案(MySQL)
1 | # Write your MySQL query statement below |