阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

124次阅读
没有评论

共计 1998 个字符,预计需要花费 5 分钟才能阅读完成。

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 关键字后的连接字段不用括号也可以正常使用。

多表连接:
– 先连接 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;

内连接:
标准写法:
select  table.column , table2.column
from table1 inner join table2 on (table1.column=table2.column);

Oracle 特殊写法:
select table.column , table2.column
from table1 ,table2
where table1.column=table2.column;

左连接:
标准写法:
select  table.column , table2.column
from table1 left join table2 on (table1.column=table2.column);

Oracle 特殊写法:
select  table.column , table2.column
from table1 ,table2
where table1.column=table2.column(+);

右连接:
标准写法:
select table.column , table2.column
from table1 right join table2 on (table1.column=table2.column);

Oracle 特殊写法:
select  table.column , table2.column
from table1 ,table2
where table1.column(+)=table2.column;

全连接:
标准写法:
select  table.column , table2.column
from table1 full join table2 on (table1.column=table2.column);

Oracle 特殊写法:
select  table.column , table2.column
from table1 ,table2
where table1.column(+)=table2.column(+);

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-10/147976.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计1998字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中