当前位置:网站首页>Syntax of SQL union query (inline, left, right, and full)
Syntax of SQL union query (inline, left, right, and full)
2022-06-23 19:44:00 【51CTO】
SQL The joint query ( inline 、 league of the left-wing writers 、 Right couplet 、 All in one ) The grammar of
summary :
The efficiency of joint query is higher , Give an example to illustrate the joint query : inline inner join 、 league of the left-wing writers left outer join 、 Right couplet right outer join 、 All in one full outer join Benefits and usage of .
The efficiency of joint query is higher , The following example illustrates a federated query ( inline 、 league of the left-wing writers 、 Right couplet 、 All in one ) The benefits of :
First of all : inline (inner join)
If you want to put user information 、 integral 、 The grades are listed , So it's usually written like this :select * from T1 ,T3 where T1.userid = T3.userid( In fact, this result is equivalent to select * from T1 inner join T3 on T1.userid=T3.userid ).
Put both tables in userid Put your lines together ( That's inline ), But the latter will be much more efficient than the former , The latter is recommended ( inline ) Writing .
SQL sentence :select * from T1 inner join T2 on T1.userid=T2.userid

second : league of the left-wing writers (left outer join)
Show left table T1 All rows in , And put the right watch T2 In the left table T1 in ; Right table T2 Does not meet the conditions , You don't have to add it to the result table , also NULL Express .
SQL sentence :select * from T1 left outer join T2 on T1.userid=T2.userid

Third : Right couplet (right outer join)
Show right table T2 All rows in , And put the left Watch T1 In the right table T2 in ; The left table T1 Does not meet the conditions , You don't have to add it to the result table , also NULL Express .
SQL sentence :select * from T1 right outer join T2 on T1.userid=T2.userid
Fourth : All in one (full outer join)
Show left table T1、 Right table T2 All lines in both sides , That is to say, the results of the leftist League + The right join result table is combined , Then filter out the duplicates .
SQL sentence :select * from T1 full outer join T2 on T1.userid=T2.userid

summary
About Union query , The efficiency is really high ,4 If you can flexibly use the combination methods , Basically, the complex sentence structure will also be simplified . this 4 One way is :1)Inner join 2)left outer join 3)right outer join 4)full outer join
【 Copyright notice 】 The copyright of this blog belongs to the author , For any form of reprint, please contact the author for authorization and indicate the source !
【 Important note 】 This article is my study record , Arguments and opinions only represent individuals and do not represent the truth of technology at that time , The goal is to learn from yourself and be fortunate enough to be an experience that can be shared with others , Therefore, mistakes will be accepted and corrected with an open mind , But it doesn't mean that the blog is correct at the moment !
【Gitee Address 】 Qin Haocheng : https://gitee.com/wjw1014
边栏推荐
- 活动报名 | MongoDB 5.0 时序存储特性介绍
- Kubernetes resource topology aware scheduling optimization
- Idea console displays Chinese garbled code
- [one by one series] identityserver4 (VIII) uses entityframework core to persist data
- 20省市公布元宇宙路线图
- SQL联合查询(内联、左联、右联、全联)的语法
- Not only Lei Jun, iqoo product manager, praised Qualcomm Xiaolong 8+: a new look
- RStudio 1.4软件安装包和安装教程
- How long do you need to prepare for the PMP Exam?
- Rendering of kotlin jetpack compose tab using animatedvisibility
猜你喜欢

Implementation of microblog system based on SSM

20 provinces and cities announce the road map of the meta universe

如何通过7个步骤编写出色的在线用户手册

直播分享| 腾讯云 MongoDB 智能诊断及性能优化实践

每日刷题记录 (二)

Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)

35 year old crisis? It has become a synonym for programmers

35歲危機?內卷成程序員代名詞了…

LeetCode 1079. movable-type printing

小程序开发框架推荐
随机推荐
函數的定義和函數的參數
String Day6 of Li Kou daily practice
基于SSM实现微博系统
如何避免基因领域“黑天鹅”事件:一场预防性“召回”背后的安全保卫战
Application de JDBC dans les essais de performance
20 provinces and cities announce the road map of the meta universe
MySQL时间函数的运用,简单问题
Crise de 35 ans? Le volume intérieur est devenu synonyme de programmeur...
FlagAI飞智:AI基础模型开源项目,支持一键调用OPT等模型
Flagai Feizhi: AI basic model open source project, which supports one click call of OPT and other models
Design of hardware switch with programmable full function rate limiter
硬件开发笔记(六): 硬件开发基本流程,制作一个USB转RS232的模块(五):创建USB封装库并关联原理图元器件
「开源摘星计划」Containerd拉取Harbor中的私有镜像,云原生进阶必备技能
金鱼哥RHCA回忆录:DO447管理用户和团队的访问--用团队有效地管理用户
LeetCode 每日一题——30. 串联所有单词的子串
[one by one series] identityserver4 (IV) authorization code process
How to install SSL certificates in Microsoft Exchange 2010
RStudio 1.4软件安装包和安装教程
增加双因素认证,不惧密码泄露,更不惧123456
Virtp4 notes