---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