---1. 普通的相等连接
select e.last_name, d.department_name
from employees e, departments d
where e.department_id = d.department_id;
---2 左外连接 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, d.department_name
from employees e, departments d
where e.department_id = d.department_id(+);
结果为:所有员工及对应部门的记录,包括没有对应部门编号department_id的员工记录。
----3. 右外连接 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, d.department_id,d.department_name
from employees e, departments d
where e.department_id(+) = d.department_id;
结果为:所有员工及对应部门的记录,包括没有任何员工的部门记录。
----4.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的员工记录和没有任何员工的部门记录。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Phoenix_99/archive/2009/12/30/5107827.aspx