【sql学习】LeetCode之175. Combine Two Tables

Table: Person

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| PersonId    | int     |
| FirstName   | varchar |
| LastName    | varchar |
+-------------+---------+
PersonId is the primary key column for this table.

Table: Address

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| AddressId   | int     |
| PersonId    | int     |
| City        | varchar |
| State       | varchar |
+-------------+---------+
AddressId is the primary key column for this table.

1)人员信息表,和人员住址表,应该是一对一的关系,通过在人员地址表中持有人员id的外键,来关联二者;

 

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

别人的代码:

Runtime: 209 ms, faster than 79.80% of MySQL online submissions for Combine Two Tables.

SELECT Person.FirstName, Person.LastName, Address.City, Address.State 
from Person 
LEFT JOIN Address on Person.PersonId = Address.PersonId;

 

你可能感兴趣的:(SQL,LeetCode刷题)