表1: Person
code
+-------------+---------+ | 列名 | 類型 | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId 是上表主鍵
表2: Address
it
+-------------+---------+ | 列名 | 類型 | +-------------+---------+ | AddressId | int | | PersonId | int | | City | varchar | | State | varchar | +-------------+---------+ AddressId 是上表主鍵
編寫一個 SQL 查詢,知足條件:不管 person 是否有地址信息,都須要基於上述兩表提供 person 的如下信息:ast
FirstName, LastName, City, State
這個使用left join on正好select
select a.FirstName, a.LastName,b.City,b.State from Person as a left join Address as b on a.PersonId = b.PersonId查詢