当前位置:网站首页>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;
边栏推荐
猜你喜欢
随机推荐
Redis笔记进阶篇:万字长文-整理Redis,各种知识点,建议收藏
基本运算符
np.unique()函数
Flexbox flex property
【博学谷学习记录】超强总结,用心分享 | 软件测试 接口测试基础
yolov5调用ip摄像头时出现的问题
DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰活性基团
ssm各类配置模板
About cross-domain issues
DAY-1 | 求两个正整数的最大公约数与最小公倍数之和——辗转相除法
2022.7.30 js notes Operators and flow controllers, loops
API 低代码开发:接口大师,一套开发、管理和提供接口的产品框架
Small program (necessary common sense for development) 1
周日数据库作业
Redis笔记基础篇:6分钟看完Redis的八种数据类型
MySql创建数据表
Brute force visitors
mysql中如何查看表是否被锁
(forwarded) HashCode summary (2)
[Remote Control Development Basic Tutorial 3] Crazy Shell Open Source Formation UAV-ADC (Joystick Control)