Home  >  Article  >  Database  >  Oracle中的左右连接

Oracle中的左右连接

WBOY
WBOYOriginal
2016-06-07 17:27:59836browse

在Oracle中左右连接省去了sql server中复杂的连接语句(left join ,right join),就用一个(+)表示。 下面做了下实验:其中查询1

在Oracle中左右连接省去了sql server中复杂的连接语句(left join ,right join),就用一个"(+)"表示。

下面做了下实验:其中查询1和查询2是等同效果的,,查询3和查询4是等同效果的。
 
查询1:
 select first_name,department_name,emp.department_id from emp,departments dept
 where emp.department_id(+)=dept.department_id;
 
122 rows selected.
 
查询2:
 select first_name,department_name,emp.department_id from departments dept left join emp
 on emp.department_id=dept.department_id;

122 rows selected. 
 
 
查询3:
 select first_name,department_name,emp.department_id from emp,departments dept
 where emp.department_id=dept.department_id(+);
 
107 rows selected.
 
查询4:
 select first_name,department_name,emp.department_id from  emp  left join departments dept
 on emp.department_id=dept.department_id;

107 rows selected.
 
 
总结:
 
1,(+)在哪一边,则返回另一边所有的记录。
 
2,(+)放在包含空值的一边,不可以两边同时使用。
 

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn