日期:2014-05-16  浏览次数:20465 次

Oracle 内连接外连接
1. 内连接很简单
select A.*, B.* from A,B where A.id = B.id
select A.*, B.* from A inner join B on A.id = B.id
以上两句是完全等价的

2. 左外连接
select * from A a left join B b on a.id=b.id
select * from A a,B b where a.id=b.id(+)

以上两句是完全等价的

3. 右外连接
select * from A a right join B b on a.id=b.id
select * from A a,B b where a.id(+)=b.id

以上两句是完全等价的

Oracle中可以使用“(+) ”来表示,9i可以使用LEFT/RIGHT/FULL OUTER JOIN

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