当前位置:网站首页>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;
边栏推荐
猜你喜欢
随机推荐
删库后!除了跑路还能干什么?
错误:with open(txt_path,‘r‘) as f: FileNotFoundError: [Errno 2] No such file or directory:
Week 7 Review
LeetCode:1161. 最大层内元素和【BFS层序遍历】
磷脂-聚乙二醇-叠氮,DSPE-PEG-Azide,DSPE-PEG-N3,MW:5000
Double Strings (don't always forget substr)
MySql创建数据表
磷脂-聚乙二醇-靶向新生血管靶向肽APRPG,DSPE-PEG-APRPG
@Autowired注解的使用
5.nodejs--cross domain, CORS, JSONP, Proxy
sh: 1: curl: not found
HCIP Day 11_MPLS Experiment
subprocess.CalledProcessError: Command ‘pip install ‘thop‘‘ returned non-zero exit status 1.
【遥控器开发基础教程1】疯壳·开源编队无人机-GPIO(遥控器指示灯控制)
Keil development environment installation tutorial
第七周复习
[Remote Control Development Basic Tutorial 3] Crazy Shell Open Source Formation UAV-ADC (Joystick Control)
周日数据库作业
rem适配
MySQL中的各种锁(行锁、间隙锁、临键锁等等LBCC)


![[详解C语言]一文带你玩转C语言小游戏---三子棋](/img/a7/1266ec8d1cc838a06fe4ff6810c0de.png)






