当前位置:网站首页>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;
边栏推荐
猜你喜欢
随机推荐
多个el-select下拉框无法选中相同内容
科研试剂DMPE-PEG-Mal 二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺
Good Key, Bad Key (思维,临项交换,经典方法)
分布式领域最重要的一篇论文,到底讲了什么?
错误:with open(txt_path,‘r‘) as f: FileNotFoundError: [Errno 2] No such file or directory:
Keil开发环境安装教程
DAY-1 | 求两个正整数的最大公约数与最小公倍数之和——辗转相除法
HCIP-第十一天-MPLS+BGP
线性代数学习笔记1:何为线性代数
磷脂-聚乙二醇-巯基,DSPE-PEG-Thiol,DSPE-PEG-SH,MW:5000
MySQL两阶段提交串讲
@Autowired注解的使用
Chapter 10 聚类
HCIP Day 11_MPLS Experiment
CV-Model【4】:MobileNet v3
【程序人生】做了多年的运维,靠什么转行拿下12K+年终奖的薪资?
线性代数学习笔记2-1:向量和向量组、线性相关性(张成空间的概念)
【遥控器开发基础教程3】疯壳·开源编队无人机-ADC(摇杆控制)
(Repost) HashCode Summary (1)
sh: 1: curl: not found









