oracle查询时几种连接方式

1 篇文章 0 订阅
1 篇文章 0 订阅

oracle查询时几种连接方式

1、内连接

只显示出两张表都匹配的结果
select * from student ,score where student.id=score.stuid//隐式内连接
select * from student  inner join score where student.id=score.stuid//显式内连接

2、外连接

有条件的显示出表的内容
1)左外连接
显示出左边表的全部字段和右边表中与左边匹配的字段,空的用null补齐
select * from student left join score on student.id=score.stuid
2)右外连接
显示出右边表的全部字段和左边表中与右边匹配的字段,空的用null补齐
select * from student right join score on student.id=score.stuid
3)全连接
显示两张表的全部字段
select * from student full join score on student.id=score.stuid

3、(+)操作符

1)这是oracle9i以前的操作符,相当于外连接
2)左外连接
select * from student, score where onstudent.id=score.stuid(+)
3)右外连接
select * from student, score where onstudent.id(+)=score.stuid

4)注意:

当使用(+)操作符执行外连接时,应当将该操作符放在显示较少行(完全满足连接条件行)一端。
(+)操作符只能出现在where子句中,并且不能与outer join语法同时使用。
当使用(+)操作符执行外连接时,如果在where语句中包含多个条件,则必须在所有的条件中都包含(+)操作符。
(+)操作符只能适用于列,而不能适用于表达式。
(+)操作符不能与or和in操作符一起使用。
(+)操作符只能用于左外连接和右外连接,不能用于实现完全连接。

4、筛选条件关键词及效率

1)on 一般做外连接时和join配合使用
2)where一般做隐式内连接使用
3)having一般存在聚合函数时必须使用
效率: on>where>having
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值