欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Oracle 外连接实现代码

程序员文章站 2024-02-08 19:50:52
1. left outer join:左外关联 select e.last_name, e.department_id, d.department_name from em...
1. left outer join:左外关联
select e.last_name, e.department_id, d.department_name
from employees e
left outer join departments d
on (e.department_id = d.department_id);
等价于
select e.last_name, e.department_id, d.department_name
from employees e, departments d
where e.department_id=d.department_id(+);
结果为:所有员工及对应部门的记录,包括没有对应部门编号department_id的员工记录。
2. right outer join:右外关联
select e.last_name, e.department_id, d.department_name
from employees e
right outer join departments d
on (e.department_id = d.department_id);
等价于
select e.last_name, e.department_id, d.department_name
from employees e, departments d
where e.department_id(+)=d.department_id;
结果为:所有员工及对应部门的记录,包括没有任何员工的部门记录。
3. full outer join:全外关联
select e.last_name, e.department_id, d.department_name
from employees e
full outer join departments d
on (e.department_id = d.department_id);
结果为:所有员工及对应部门的记录,包括没有对应部门编号department_id的员工记录和没有任何员工的部门记录。