当前位置:网站首页>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 joinIndicates internal connection ;
left joinLeft outer connection ;
right joinRight outer connection ;
full joinIndicates full external connection ;
onClause is used to specify the connection condition .
- If you use
fromClause specifies the inside 、 External connection , You have to useonClause specifies the connection condition ;
- If you use (
+) Operator specifies the outer join , Must be usedwhereClause specifies the connection condition .
Two 、 Internal connection (Inner Join/Join)
2.1 Inner Join
Inner join2.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 joinSQL> 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 joinSQL> 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 joinoracleSelect 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

边栏推荐
- STM32+MFRC522完成IC卡号读取、密码修改、数据读写
- win10系统下插入U盘有声音提示却不显示盘符
- Execution process of MySQL query request - underlying principle
- Jdbc driver, c3p0, druid and jdbctemplate dependent jar packages
- There is a sound prompt when inserting a USB flash disk under win10 system, but the drive letter is not displayed
- Docker installation redis
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- Test 123
- Penetration test information collection - WAF identification
- Docker安装Redis
猜你喜欢

二叉搜索树

Docker installation redis

44 colleges and universities were selected! Publicity of distributed intelligent computing project list

CSRF漏洞分析

None of the strongest kings in the monitoring industry!
![[the 300th weekly match of leetcode]](/img/a7/16b491656863e2c423ff657ac6e9c5.png)
[the 300th weekly match of leetcode]

30 minutes to understand PCA principal component analysis

Self supervised heterogeneous graph neural network with CO comparative learning

wx小程序学习笔记day01

一种用于夜间和无袖测量血压手臂可穿戴设备【翻译】
随机推荐
Self-supervised Heterogeneous Graph Neural Network with Co-contrastive Learning 论文阅读
使用block实现两个页面之间的传统价值观
Cocos2d Lua smaller and smaller sample memory game
First, look at K, an ugly number
bonecp使用数据源
Why does wechat use SQLite to save chat records?
Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法
[the 300th weekly match of leetcode]
2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目
Hongke shares | plate by plate ar application in Beijing Winter Olympics
人体骨骼点检测:自顶向下(部分理论)
Execution process of MySQL query request - underlying principle
DOM简要
From 2022 to 2024, the list of cifar azrieli global scholars was announced, and 18 young scholars joined 6 research projects
用于远程医疗的无创、无袖带血压测量【翻译】
一种用于夜间和无袖测量血压手臂可穿戴设备【翻译】
Some understandings of tree LSTM and DGL code implementation
Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
复现Thinkphp 2.x 任意代码执行漏洞
epoll()无论涉及wait队列分析