题目
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
代码
一个左外连接就行了。
# Write your MySQL query statement below
select FirstName, LastName, City, State
from Person left outer join Address
on Person.PersonID = Address.PersonID;
本文介绍了一个SQL查询案例,通过左外连接实现从Person表中获取每个人的姓名,并从Address表中匹配对应的城市和州信息,即使某些人没有地址记录也能完整列出。
119

被折叠的 条评论
为什么被折叠?



