当前位置:网站首页>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
边栏推荐
- 星诺奇科技IPO被终止:曾拟募资3.5亿元 年营收3.67亿
- [Sun Yat sen University] information sharing of postgraduate entrance examination and re examination
- CSRF漏洞分析
- STM32+MFRC522完成IC卡号读取、密码修改、数据读写
- Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法
- Coco2017 dataset usage (brief introduction)
- Self supervised heterogeneous graph neural network with CO comparative learning
- SQL injection Foundation
- AvL树的实现
- Method of accessing mobile phone storage location permission under non root condition
猜你喜欢
44 colleges and universities were selected! Publicity of distributed intelligent computing project list
Tree-LSTM的一些理解以及DGL代码实现
wx小程序学习笔记day01
裕太微冲刺科创板:拟募资13亿 华为与小米基金是股东
Penetration test information collection - CDN bypass
Easy to use PDF to SVG program
根据PPG估算血压利用频谱谱-时间深度神经网络【翻】
【中山大学】考研初试复试资料分享
Self supervised heterogeneous graph neural network with CO comparative learning
Introduction and case analysis of Prophet model
随机推荐
DOM Brief
From 2022 to 2024, the list of cifar azrieli global scholars was announced, and 18 young scholars joined 6 research projects
Why does wechat use SQLite to save chat records?
POJ 2208 six lengths of tetrahedron are known, and the volume is calculated
Grafana 9.0 is officially released! It's the strongest!
Excellent open source fonts for programmers
STM32+HC05串口蓝牙设计简易的蓝牙音箱
Mathematics in machine learning -- common probability distribution (XIII): Logistic Distribution
[swoole series 2.1] run the swoole first
Maixll dock camera usage
This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
C语言高校实验室预约登记系统
Echart simple component packaging
First, look at K, an ugly number
当保存参数使用结构体时必备的开发技巧方式
Introduction and case analysis of Prophet model
用友OA漏洞学习——NCFindWeb 目录遍历漏洞
Cobra 快速入门 - 专为命令行程序而生
Tree-LSTM的一些理解以及DGL代码实现
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools