当前位置:数据库 > Oracle >>

oracle中的左右连接

oracle中的左右连接
 
在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,(+)放在包含空值的一边,不可以两边同时使用。
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,