175. Combine Two Table

Leetcode 問題: 175. Combine Two Table

題目

PersonAddress 資料表,Person 不一定會有 Address

在不管有沒有 Address 的條件撈取出 FirstName,LastName, City, State 欄位資料

Person 資料表

Column Name Type
PersonId int
FirstName varchar
LastName varchar

Address 資料表

Column Name Type
AddressId int
PersonId int
City varchar
State varchar

答案

# Write your MySQL query statement below
SELECT `FirstName`, `LastName`, `City`, `State`
FROM `Person`
    LEFT JOIN `Address` ON
    `Person`.`PersonId` = `Address`.`PersonId`

參考資料