LeetCode--175.组合两个表

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-I2RfS4BK-1601343899241)(59D802C405E24745B8910D2755A192FA)]

基于上述两表提供person信息,说明按person进行外连接

建表语句

Create table Person (PersonId int,FirstName varchar(255), LastName varchar(255));
Create table Address (AddressId int,PersonId int, City varchar(255), State varchar(255));
Truncate table Person;
insert into Person (PersonId, LastName,FirstName) values ('1', 'Wang', 'Allen');
Truncate table Address;
insert into Address (AddressId, PersonId,City, State) values ('1', '2', 'New York City', 'New York');

答案

select p.FirstName,p.LastName,a.City,a.State from Person p
left join Address a on a.PersonId =p.PersonId
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页