【LeetCode】组合两个表(mysql)

题目

编写解决方案,报告 Person 表中每个人的姓、名、城市和州。如果 personId 的地址不在 Address 表中,则报告为 null 。

以 任意顺序 返回结果表。

结果格式如下所示。

select firstName ,lastName,city,state

from Person

left join Address

on Person.personId = Address.PersonId

这段SQL代码是用来从person表中选择firstNamelastNamecitystate字段,并与Address表进行左连接(left join)。左连接会返回所有的person记录,即使在Address表中没有匹配的记录。

具体方法参考:联表查询中的左联查询(left join )

https://blog.csdn.net/m0_67930426/article/details/134321937https://blog.csdn.net/m0_67930426/article/details/134321937

相关推荐
在风中的意志8 小时前
[数据库SQL] [leetcode-584] 584. 寻找用户推荐人
数据库·sql·leetcode
毅炼8 小时前
hot100打卡——day08
java·数据结构·算法·leetcode·深度优先
leoufung14 小时前
LeetCode 67. Add Binary:从面试思路到代码细节
算法·leetcode·面试
无限进步_14 小时前
【C语言】循环队列的两种实现:数组与链表的对比分析
c语言·开发语言·数据结构·c++·leetcode·链表·visual studio
linsa_pursuer15 小时前
最长连续序列
java·数据结构·算法·leetcode
POLITE315 小时前
Leetcode 54.螺旋矩阵 JavaScript (Day 8)
javascript·leetcode·矩阵
only-qi16 小时前
LeetCode 148. 排序链表
算法·leetcode·链表
smj2302_7968265216 小时前
解决leetcode第3791题.给定范围内平衡整数的数目
python·算法·leetcode
不能只会打代码16 小时前
力扣--1970. 你能穿过矩阵的最后一天(Java)
java·算法·leetcode·二分查找·力扣·bfs·最后可行时间
光明西道45号16 小时前
Leetcode 15. 三数之和
数据结构·算法·leetcode