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.
总结:(+)在哪一边,则返回另一边所有的记录。