当前位置:网站首页>oracle inner join and outer join
oracle inner join and outer join
2022-08-02 03:32:00 【Tom has no Cat】
一、表的连接
1.内连接 (inner join)
What you get by doing an inner join isa和bThe columns of the association relationship exist at the same time to be connected,after inlinea和bThe associated columns are the samea中数据和bThe data are combined to form a new table data.
Inner joins will only display data that satisfies the condition
-- a 表和 b 表做内连接
-- a 表中的 bNO 和 b 表中的 NO 都不为 null 且a.bNo=b.NO form a new piece of data.
SELECT * FROM a INNER JOIN b ON(a.bNO=b.NO);
Equijoin is also an inner join
SELECT * FROM a, b WHERE a.nNO=b.NO;
2.外连接
2.1 左外连接(left outer join:简写为 left join)
Left outer join is a All rows in the table are displayed,b表 The corresponding data in are added in a The corresponding data in the table is followed by new table data.
-- a 表和 b The table is left join
-- a All columns in the table will have,b Only and in the table a The data associated with the table will follow a The table corresponds to the data behind
SELECT * FROM a LEFT JOIN b ON(a.bNO=b.NO);
在 oracle Another way of writing middle-left join:
SELECT * FROM a, b WHERE a.bNO = b.NO(+);
2.2 右外连接(right outer join :简写为 right join)
A right outer join is the opposite of a left outer join, bAll rows in the table are displayed,a 表 The corresponding data in are added in b The corresponding data in the table is followed by new table data.
-- a 表和 b Do a right join on the table
-- b All columns in the table will have,a Only and in the table b The data associated with the table will follow b The table corresponds to the data behind
SELECT * FROM a RIGHT JOIN b ON(a.bNO=b.NO);
在 oracle Another way of writing middle right join
SELECT * FROM a, b WHERE a.bNo(+) = b.NO;
2.3 全外连接(full outer join:简写为 full join)
a 表和 b The data in the table is displayed
-- a 表和 b The table is fully joined
-- a 表和 b The data in the table is displayed
SELECT * FROM a FULL JOIN b ON(a.bNO=b.NO);
3、数据集合操作
3.1 union 和 union all (并集操作)
union 和 union all 都是将多个 select The collection obtained by the query is subjected to the union operation.
使用前提:
要使用 union 或者 union all Multiple to merge select The number of queried collection fields must be the same,The corresponding field types should also be the same.
二者的区别:
union The merged results were deduplicated,union all Just merged,The merged set is not deduplicated;
union The merged collection will be sorted by default according to the order of the fields,union all 并不会进行排序;
注:
union 的效率比 union all 的效率低,所以,Use if you want to deduplicate the merged set union,Used without deduplication union all;
--union:The results obtained are only half of the first select 语句的值(进行了去重操作,And also the default sorting)
SELECT * FROM a UNION SELECT * FROM b;
--union all:The result obtained is twoselect A collection of statements merged together(No deduplication and no sorting)
SELECT * FROM a UNION ALL SELECT * FROM b;
3.2 intersect (交集操作)
intersect The operation is to combine multiple select The collection obtained by the query is subjected to the intersection operation
-- intersect:得到的是两个 select 语句的公共部分(即交集部分)
SELECT * FROM a INTERSECT SELECT * FROM b;
3.3 minus (差集操作)
minus The operation is to combine multiple select Intersection operation is performed on the obtained difference sets
-- minus:Got the previous one selectQuery out there and the latter select 没有的
SELECT * FROM a MINUS SELECT * FROM b;
边栏推荐
- A senior test engineer asked me these questions as soon as the interview came
- 【C语言万字长文】 宏定义 结构体 共用体 内存对齐知识点总结
- Brute force visitors
- 线性代数学习笔记3-2:矩阵乘法的理解
- RHCSA第二天
- [Remote Control Development Basic Tutorial 3] Crazy Shell Open Source Formation UAV-ADC (Joystick Control)
- SSM整合
- 磷脂-聚乙二醇-酰肼,DSPE-PEG-Hydrazide,DSPE-PEG-HZ,MW:5000
- 2022年比若依更香的开源项目
- 第七周复习
猜你喜欢
随机推荐
DAY-1 | 求两个正整数的最大公约数与最小公倍数之和——辗转相除法
手把手带你 Unity 入门之从零创建一个时钟(GameObjects 与 Scripts)
LeetCode:1161. 最大层内元素和【BFS层序遍历】
PowerManagerService灭屏超时流程
离线数仓-用户行为采集
@ApiModel 和 @ApiModelProperty
Week 7 Review
磷脂-聚乙二醇-叠氮,DSPE-PEG-Azide,DSPE-PEG-N3,MW:5000
分布式领域最重要的一篇论文,到底讲了什么?
周日数据库作业
线性代数学习笔记3-2:矩阵乘法的理解
oracle内连接和外连接
线性代数学习笔记1:何为线性代数
错误:with open(txt_path,‘r‘) as f: FileNotFoundError: [Errno 2] No such file or directory:
Daily practice------There are n integers, so that the previous numbers are moved back m positions in order, and the last m numbers become the first m numbers
DOM destruction and reproduction experiment
活体检测 Adaptive Normalized Representation Learning for GeneralizableFace Anti-Spoofing 阅读笔记
Redis笔记基础篇:6分钟看完Redis的八种数据类型
mysql创建表
day11--shell脚本









