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操作符一起使用。
(+)操作符只能用于左外连接和右外连接,不能用于实现完全连接。
当使用(+)操作符执行外连接时,应当将该操作符放在显示较少行(完全满足连接条件行)一端。
(+)操作符只能出现在where子句中,并且不能与outer join语法同时使用。
当使用(+)操作符执行外连接时,如果在where语句中包含多个条件,则必须在所有的条件中都包含(+)操作符。
(+)操作符只能适用于列,而不能适用于表达式。
(+)操作符不能与or和in操作符一起使用。
(+)操作符只能用于左外连接和右外连接,不能用于实现完全连接。
4、筛选条件关键词及效率
1)on 一般做外连接时和join配合使用
2)where一般做隐式内连接使用
3)having一般存在聚合函数时必须使用
效率: on>where>having