--- tags: sql, LeetCode disqus: HackMD --- # 175. Combine Two Tables (資訊來自於`leetcode 175`[ Combine Two Tables](https://leetcode.com/problems/combine-two-tables/?envType=study-plan&id=sql-i)) ### 合併兩個表  編寫 SQL 查詢以報告 Person 表中每個人的名字、姓氏、城市和州。如果地址表中不存在 personId 的地址,則改為報告 null。 ### 題目: 地址表中沒有 personId = 1 的地址,所以我們在他們的城市和州返回 null。 addressId = 1 包含有關 personId = 2 的地址的信息。  ### 解題方式: ```sql= select M.firstName,M.lastName,A.city,A.state from Person M left outer join Address A on A.personId = M.personId ``` ### 解題解析: 運用outer join 來把兩個table相加,而沒有城市或是州的資料則會傳回NULL
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up