当前位置:网站首页>Oracle advanced (IV) table connection explanation
Oracle advanced (IV) table connection explanation
2022-07-06 18:45:00 【InfoQ】
One 、 Preface
- Internal connection ( Natural join )
- External connection (1) The left outer join ( The table on the left is unrestricted )(2) Right connection ( The table on the right is unrestricted )(3) Full outer join ( There are no restrictions on the left and right tables )
- Self join ( Connections in the same table )
select table1.column,table2.column from table1 [inner | left | right | full ] join table2 on table1.column1 = table2.column2;
inner join
Indicates internal connection ;
left join
Left outer connection ;
right join
Right outer connection ;
full join
Indicates full external connection ;
on
Clause is used to specify the connection condition .
- If you use
from
Clause specifies the inside 、 External connection , You have to useon
Clause specifies the connection condition ;
- If you use (
+
) Operator specifies the outer join , Must be usedwhere
Clause specifies the connection condition .
Two 、 Internal connection (Inner Join/Join)
2.1 Inner Join
Inner join
2.2 Illustrate with examples
SQL> select * from dave;
ID NAME
1 dave
2 bl
1 bl
2 dave
SQL> select * from bl;
ID NAME
1 dave
2 bl
SQL> Select a.id,a.name,b.name from dave a inner join bl b on a.id=b.id; -- Standard writing
ID NAME NAME
1 dave dave
2 bl bl
1 bl dave
2 dave bl
SQL> Select a.id,a.name,b.name from dave a join bl b on a.id=b.id; -- Omit here inner keyword
ID NAME NAME
1 dave dave
2 bl bl
1 bl dave
2 dave bl
SQL> Select a.id,a.name,b.name from dave a,bl b where a.id=b.id; -- select Multi-table query
ID NAME NAME
1 dave dave
2 bl bl
1 bl dave
2 dave bl
2.3 Natural join (Natural join)
SQL> Select id,name from dave a natural join bl b;
ID NAME
1 dave
2 bl
SQL> Select dave.id,bl.name From dave join bl on dave.id = bl.id and dave.name=bl.name;
ID NAME
1 dave
2 bl
- If there are multiple fields of two tables with natural connection that have the same name and type , Then they will be regarded as the condition of natural connection .
- If two naturally connected tables only have the same field name , But the data types are different , Then an error will be returned .
3、 ... and 、 External connection (Outer Join)
- (+) Operators can only appear in where clause , And not with outer join Grammar is used at the same time .
- When using (+) When the operator performs an outer join , If in where Clause contains multiple conditions , Must include... In all conditions (+) The operator
- (+) The operator applies only to columns , It can't be used in expressions .
- (+) Operators cannot be associated with or and in Operators are used together .
- (+) Operators can only be used to implement left outer join and right outer join , It cannot be used to realize full external connection .
SQL> select * from bl;
ID NAME
1 dave
2 bl
3 big bird
4 exc
9 Huaining
SQL> select * from dave;
ID NAME
8 Anqing
1 dave
2 bl
1 bl
2 dave
3 dba
4 sf-express
5 dmm
3.1 The left outer join (Left outer join/ left join)
left join
SQL> select * from dave a left join bl b on a.id = b.id;
ID NAME ID NAME
1 bl 1 dave
1 dave 1 dave
2 dave 2 bl
2 bl 2 bl
3 dba 3 big bird
4 sf-express 4 exc
5 dmm -- here B The table is null, Because there is no match to
8 Anqing -- here B The table is null, Because there is no match to
SQL> select * from dave a left outer join bl b on a.id = b.id;
ID NAME ID NAME
1 bl 1 dave
1 dave 1 dave
2 dave 2 bl
2 bl 2 bl
3 dba 3 big bird
4 sf-express 4 exc
5 dmm
8 Anqing
+
+
+
SQL> Select * from dave a,bl b where a.id=b.id(+); -- Be careful : use (+) You have to use keywords where
ID NAME ID NAME
1 bl 1 dave
1 dave 1 dave
2 dave 2 bl
2 bl 2 bl
3 dba 3 big bird
4 sf-express 4 exc
5 dmm
8 Anqing
3.2 Right connection (right outer join/ right join)
left join
SQL> select * from dave a right join bl b on a.id = b.id;
ID NAME ID NAME
1 dave 1 dave
2 bl 2 bl
1 bl 1 dave
2 dave 2 bl
3 dba 3 big bird
4 sf-express 4 exc
9 Huaining -- The left table here is not enough Null fill
-- Have chosen 7 That's ok .
SQL> select * from dave a right outer join bl b on a.id = b.id;
ID NAME ID NAME
1 dave 1 dave
2 bl 2 bl
1 bl 1 dave
2 dave 2 bl
3 dba 3 big bird
4 sf-express 4 exc
9 Huaining -- The left table here is not enough Null fill
-- Have chosen 7 That's ok .
+
+
SQL> Select * from dave a,bl b where a.id(+)=b.id;
ID NAME ID NAME
1 dave 1 dave
2 bl 2 bl
1 bl 1 dave
2 dave 2 bl
3 dba 3 big bird
4 sf-express 4 exc
9 Huaining
3.3 Full outer join (full outer join/ full join)
null
+
SQL> select * from dave a full join bl b on a.id = b.id;
ID NAME ID NAME
8 Anqing
1 dave 1 dave
2 bl 2 bl
1 bl 1 dave
2 dave 2 bl
3 dba 3 big bird
4 sf-express 4 exc
5 dmm
9 Huaining
-- Have chosen 9 That's ok .
SQL> select * from dave a full outer join bl b on a.id = b.id;
ID NAME ID NAME
8 Anqing
1 dave 1 dave
2 bl 2 bl
1 bl 1 dave
2 dave 2 bl
3 dba 3 big bird
4 sf-express 4 exc
5 dmm
9 Huaining
Four 、 Self join
self join
oracle
Select worker.name,Mgr.name From worker,mgr Where worker.id = mgr.id;
select work.ename worker,mgr.ename manager from scott.emp work, scott.emp mgr where work.mgr = mgr.empno order by work.ename;
WORKER MANAGER
ADAMS SCOTT
ALLEN BLAKE
BLAKE KING
CLARK KING
FORD JONES
JAMES BLAKE
JONES KING
MARTIN BLAKE
MILLER CLARK
SCOTT JONES
SMITH FORD
WORKER MANAGER
TURNER BLAKE
WARD BLAKE
5、 ... and 、 Connection diagram
边栏推荐
- 根据PPG估算血压利用频谱谱-时间深度神经网络【翻】
- [sword finger offer] 60 Points of N dice
- Huawei 0 foundation - image sorting
- 基于ppg和fft神经网络的光学血压估计【翻译】
- 美庐生物IPO被终止:年营收3.85亿 陈林为实控人
- AcWing 3537. Tree lookup complete binary tree
- C language college laboratory reservation registration system
- Interpreting cloud native technology
- Use cpolar to build a business website (1)
- 星诺奇科技IPO被终止:曾拟募资3.5亿元 年营收3.67亿
猜你喜欢
Some understandings of tree LSTM and DGL code implementation
Docker installation redis
Self-supervised Heterogeneous Graph Neural Network with Co-contrastive Learning 论文阅读
[Sun Yat sen University] information sharing of postgraduate entrance examination and re examination
win10系统下插入U盘有声音提示却不显示盘符
Self supervised heterogeneous graph neural network with CO comparative learning
The role of applet in industrial Internet
小程序在产业互联网中的作用
用于远程医疗的无创、无袖带血压测量【翻译】
Easy to use PDF to SVG program
随机推荐
安装及管理程序
Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目
上海部分招工市場對新冠陽性康複者拒絕招錄
【LeetCode第 300 场周赛】
爬虫玩得好,牢饭吃到饱?这3条底线千万不能碰!
There is a sound prompt when inserting a USB flash disk under win10 system, but the drive letter is not displayed
node の SQLite
UFIDA OA vulnerability learning - ncfindweb directory traversal vulnerability
Docker安装Redis
具体说明 Flume介绍、安装和配置
Splay
This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
Human bone point detection: top-down (part of the theory)
首先看K一个难看的数字
44所高校入选!分布式智能计算项目名单公示
基于ppg和fft神经网络的光学血压估计【翻译】
使用block实现两个页面之间的传统价值观
2022/02/12
POJ 2208 six lengths of tetrahedron are known, and the volume is calculated