当前位置:网站首页>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

边栏推荐
- wx小程序学习笔记day01
- 287. Find duplicates
- Top command details
- Splay
- Breadth first traversal of graph
- How does crmeb mall system help marketing?
- DOM Brief
- Some recruitment markets in Shanghai refuse to recruit patients with covid-19 positive
- DOM简要
- The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
猜你喜欢
星诺奇科技IPO被终止:曾拟募资3.5亿元 年营收3.67亿
测试行业的小伙伴,有问题可以找我哈。菜鸟一枚~
Medical image segmentation
被疫情占据的上半年,你还好么?| 2022年中总结
AvL树的实现
根据PPG估算血压利用频谱谱-时间深度神经网络【翻】
MySQL查询请求的执行过程——底层原理
【LeetCode第 300 场周赛】
Self supervised heterogeneous graph neural network with CO comparative learning
Penetration test information collection - WAF identification
随机推荐
具体说明 Flume介绍、安装和配置
Penetration test information collection - CDN bypass
node の SQLite
简单易用的PDF转SVG程序
AcWing 3537. Tree lookup complete binary tree
MySQL查询请求的执行过程——底层原理
30 minutes to understand PCA principal component analysis
From 2022 to 2024, the list of cifar azrieli global scholars was announced, and 18 young scholars joined 6 research projects
解读云原生技术
C语言高校实验室预约登记系统
一种用于夜间和无袖测量血压手臂可穿戴设备【翻译】
CSRF漏洞分析
POJ 2208 six lengths of tetrahedron are known, and the volume is calculated
Collection of penetration test information -- use with nmap and other tools
Why does wechat use SQLite to save chat records?
随着MapReduce job实现去加重,多种输出文件夹
JDBC驱动器、C3P0、Druid和JDBCTemplate相关依赖jar包
Unity资源顺序加载的一个方法
epoll()无论涉及wait队列分析
Alibaba cloud international ECS cannot log in to the pagoda panel console