oracle 表连接特有写法与标准写法

简介:

oracle里表连接支持标准写法,但也有oracle特殊的写法,这两种写法在某些场景下会有差异,推荐使用标准写法,这里只是介绍表连接标准语法及了解oracle的特殊写法。

标准连接语法:

select table1.column , table2.column

from table1

[corss join table2]

[national jon table2]

[join table2 using (column)]

[join table2 on (table1.column=table2.column)]

[left | right | full outer join table2 on (table1.column=table2.column)];


实际使用中on关键字后的连接字段不用括号也可以正常使用。


多表连接:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--先连接table4和table5并将其结果集命名为table2,再与table1连接
select  table1. column ,table2. column 
from  table1 
  inner  join 
(  select  table4. column ,table5. column 
    from  table4  inner  join  table5 
    on  table4. column  =table5. column  )  as  table2  
on  table1. column =table2. column ;
 
等同于
select  table1. column  ,table2. column
from  table1 ,( select  table4. column ,table5. column 
                   from  table4,table5 
                   where  table4. column =table5. column )  as  table2
where  table1. column =table2. column ;
 
 
--连接table1,table2,table3,没有连接顺序之分
select  table1. column ,table2. column ,table3. column 
from  table1  inner  join  table2 
          on   table1. column =table2. column
          inner  join  table3
          on  table1. column =table3. column ;
 
等同于
select  table1. column ,table2. column ,table3. column 
from  table1,table2.table3
where  table1. column =table2. column  and   table1. column =table3. column ;


内连接:

标准写法:

1
2
select   table . column  , table2. column 
from  table1  inner  join  table2  on  (table1. column =table2. column );

oracle 特殊写法:

1
2
3
select  table . column  , table2. column
from  table1 ,table2
where  table1. column =table2. column ;


左连接:

标准写法:

1
2
select    table . column  , table2. column 
from  table1  left  join  table2  on  (table1. column =table2. column );

oracle 特殊写法:

1
2
3
select   table . column  , table2. column 
from  table1 ,table2
where  table1. column =table2. column (+);


右连接:

标准写法:

1
2
select  table . column  , table2. column 
from  table1  right  join  table2  on  (table1. column =table2. column );

oracle 特殊写法:

1
2
3
select    table . column  , table2. column 
from  table1 ,table2
where  table1. column (+)=table2. column ;


全连接:

标准写法:

1
2
select   table . column  , table2. column 
from  table1  full  join  table2  on  (table1. column =table2. column );

oracle 特殊写法:

1
2
3
select   table . column  , table2. column 
from  table1 ,table2
where  table1. column (+)=table2. column (+);



本文转自 天黑顺路 51CTO博客,原文链接:http://blog.51cto.com/mjal01/1975625,如需转载请自行联系原作者
相关文章
|
SQL 存储 Oracle
Oracle之3种表连接方式(排序合并连接、嵌套循环、哈希连接)
Oracle之3种表连接方式(排序合并连接、嵌套循环、哈希连接) 排序合并连接 1.2.4.2.1  排序合并连接 排序合并连接(Sort Merge Join)是一种两个表在做表连接时用排序操作(Sort)和合并操作(Merge)来得到连接结果集的表连接方法。
4051 0
|
SQL Oracle 关系型数据库
Oracle中的分组查询、子查询、多表连接
Oracle中的分组查询、子查询、多表连接
608 0
Oracle中的分组查询、子查询、多表连接
|
SQL Oracle 关系型数据库
Oracle表连接
Oracle表连接
327 0
|
Oracle 关系型数据库 索引
Oracle优化之表连接方式
Oracle优化之表连接方式在Oracle数据库中,两个表之间的表连接方法有排序合并连接、嵌套循环连接、哈希连接和笛卡尔连接四种 1.排序合并连接(sort merge join)   排序合并连接是一种两表在做表连接时用排序(SORT)操作和合并(MERGE)操作来得到连接结果集的表连接方法  ...
1563 0
|
SQL Oracle 关系型数据库
Oracle中表连接方式(Nested Loop、Hash join)对于表访问次数的测试
介绍了sql多表连接的几种方式,如有不正确的地方请指正。
4604 0
|
Oracle 关系型数据库 索引
|
SQL Oracle 关系型数据库
|
Oracle 关系型数据库
|
SQL Oracle 关系型数据库
ORACLE表连接方式分析及常见用法
摘要: 针对在数据仓库环境下,由于超大数据量的处理而产生的效率问题,本文深入分析了ORACLE表的几种连接方式、特点、适用范围,以及对于如何使用和优化做了详细的探讨。 关键字: 数据仓库 ORACLE 表连接 一 引言 数据仓库技术是目前已知的比较成熟和被广泛采用的解决方案,用于整和电信运营企业内部所有分散的原始业务数据,并通过便捷有效的数据访问手段,可以支持企业内部不同部门,不同需求,不同层次的用户随时获得自己所需的信息。
1357 0

推荐镜像

更多