LeetCode刷题实战175:组合两个表
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
题意
解题
#如果某个person在Address表中没有记录,则City、State为空
select p.FirstName, p.LastName, a.City, a.State
from Person p
#左外连接,person表是主表
left outer join Address a
#连接条件,PersonId相同
on p.PersonId = a.PersonId;
赞 (0)