日誌2024-10-30 02:19
【Leetcode】175. Combine Two Tables作者:Chris
Person表格屬性 | |
Column Name | Type |
personId | int |
lastName | varchar |
firstName | varchar |
Address表格屬性 | |
Column Name | Type |
addressId | int |
personId | int |
city | varchar |
state | varchar |
personId | lastName | firstName |
1 | Wang | Allen |
2 | Alice | Bob |
addressId | personId | city | state |
1 | 2 | New York City | New York |
2 | 3 | Leetcode | California |
firstName | lastName | city | state |
Allen | Wang | Null | Null |
Bob | Alice | New York City | New York |
個人理解 |
典型的Left Join案例,如果寫on會造成一長串程式碼的話,可以改用using來替代,達到精簡程式碼的目的。 |
程式碼 |
select firstName,lastName,city,state from Person left join Address on Person.personId = Address.personId; |
或 |
select firstName,lastName,city,state from Person left join Address using(personId); |