首页 > 其他分享 >join、left join、right join、full join的区别

join、left join、right join、full join的区别

时间:2022-09-29 17:46:35浏览次数:44  
标签:right join no full test select

join:内连接
left join:左外连接
right join:右外连接
full join/full outer join:全外连接

例如有A表数据如下:

B表数据如下:

join:取两表相同的部分
select * from test.test_a a
join test.test_b b
on a.t_no =b.t_no

left join:取左边表的全部行,没有匹配上的数据用空值填补
select * from test.test_a a
left join test.test_b b
on a.t_no =b.t_no

right join:取右边表的全部行,没有匹配上的数据用空值填补
select * from test.test_a a
right join test.test_b b
on a.t_no =b.t_no

full join:取两表的全部行,两表数据一致的在同一行,两表数据不一致的单独显示一行,没有匹配上的数据用空值填补
select * from test.test_a a
full join test.test_b b
on a.t_no =b.t_no

因此,如果想要取两表不同部分的数据
select * from test.test_a a
full join test.test_b b
on a.t_no =b.t_no
where a.t_no is null or b.t_no is null

等同于:left join + union all + right join
select * from test.test_a a
left join test.test_b b
on a.t_no =b.t_no
where b.t_no is null
union all
select * from test.test_a a
right join test.test_b b
on a.t_no =b.t_no
where a.t_no is null

标签:right,join,no,full,test,select
From: https://www.cnblogs.com/hq0202/p/16669795.html

相关文章

  • os.path.join()
    os.path.join()函数:连接两个或更多的路径名组件如果拼接在后的参数中含有'\'开头的参数,将从'\'开头的参数开始,前面的参数均将失效,并且路径将从对应磁盘的根目录开始。im......
  • 【PlayWright】报错:AttributeError: 'PlaywrightContextManager' object has no attri
    1.问题分析1.1.公司云桌面win7系统把之前C盘中自带的py3.7环境给还原了,之前跑得好好的PlayWright案例不能运行了2.解决过程2.1.参考网上的解决方案,说是node的版本问题......
  • elsarticle 模板提示 Overfull \hbox (2.61108pt too wide) 问题的解决
    在用Elsevier提供的elsarticle模板写作时,编译提示:Overfull\hbox(2.61108pttoowide)一般情况下,该提示是说程序找不到合适的换行点,导致某行文字太满(Overfull),但这......
  • Left Right Operation
    ProblemStatementYouaregivenanintegersequenceoflength$N$:$A=(A_1,A_2,\ldots,A_N)$.Youwillperformthefollowingconsecutiveoperationsjustonce:......
  • Full House
    ProblemStatementWehavefivecardswithintegers$A$,$B$,$C$,$D$,and$E$writtenonthem,oneoneachcard.ThissetoffivecardsiscalledaFullhouse......
  • javascript数组的reduce()与reduceRight()方法
    javascript数组的reduce()与reduceRight()方法reduce()方法按照数组元素的先后顺序,分别对数组元素执行一次由程序员提供的回调函数(这个回调函数被称作reducer函数);每一......
  • 微软出品自动化神器Playwright,不用写一行代码(Playwright+Java)系列(三) 之 手把手带你
    写在前面官方给的栗子是Junit,但是我还是用TestNG来进行脚本的编写,这里只分享思路,不管是哪个测试框架基本思路都是一样的,喜欢用官方的Junit的,建议查看官方文档。如何编写......
  • split() join() 的区别
    split是字符串的方法,将字符串按照特定标志分割成数组例:“u&s”.split(“&”)------ [“u”,”s”]join:是数组方法,将数组按标志组合成字符串 [“u”,”s”].join(“-......
  • SCPNet: Spatial-Channel Parallelism Network for Joint Holistic and Partial Perso
    摘要:完整图像的行人重识别在过去几年里获得了广泛研究并取得了长足的进步。然而,在现实场景中,行人往往会被物体或他人遮挡,造成partial的行人识别变得困难。本文提出了空间维......
  • MySQL的join算法优化
    在Mysql的实现中,Nested-LoopJoin有3种实现的算法:SimpleNested-LoopJoin:SNLJ,简单嵌套循环连接IndexNested-LoopJoin:INLJ,索引嵌套循环连接BlockNested-LoopJoin:BN......