【LeetCode】组合两个表(mysql)

题目

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

以 任意顺序 返回结果表。

结果格式如下所示。

答

select firstName ,lastName,city,state

from Person

left join Address

on Person.personId = Address.PersonId

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

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

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

相关推荐
longlongzihan4 分钟前
LeetCode 283. 移动零:从辅助数组到双指针原地算法
c++·算法·leetcode
longlongzihan14 小时前
LeetCode 5. 最长回文子串:从暴力匹配到中心扩展的思维演进
c++·算法·leetcode
苦瓜打怪兽14 小时前
leetcode 热题100(11. 盛最多水的容器)
python·算法·leetcode
All for pursuit.18 小时前
【回溯-6】79.单词搜索
数据结构·c++·算法·leetcode
Navigator_Z19 小时前
LeetCode //C - 1281. Subtract the Product and Sum of Digits of an Integer
c语言·算法·leetcode
旖旎夜光21 小时前
LeetCode 1576: 替换所有的问号(模拟) —— 题解
c++·学习·算法·leetcode·力控
longlongzihan21 小时前
回溯法详解:LeetCode 46. 全排列
算法·leetcode·回溯
圣保罗的大教堂1 天前
leetcode 3532. 针对图的路径存在性查询 I 中等
leetcode
longlongzihan1 天前
从LeetCode 70. 爬楼梯看动态规划:如何精准推导状态转移方程?
c++·算法·leetcode·动态规划
Rnan-prince2 天前
LeetCode 股票买卖系列:一个动态规划状态机模板通吃四题
leetcode·动态规划