?LeetCode刷題實戰(zhàn)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;
評論
圖片
表情
