select e.last_name,d.department_name
from employees e,departments d
where last_name='grant'and e.department_id = d.department_id
等價於:
select e.last_name,d.department_name
from employees e join departments d on e.department_id=d.department_id
where last_name='grant'
lesson 7
natural joins(等值連線)
-natural join 要求連線的兩列資料型別相同(等值連線);不用指定列,自動匹配名字內容相同的類;
-using clause using 加的列的名字不能在其他子句中限定條件;
-on clause on指定條件;(相當於where);
lesson 8
非等值連線
select e.ename,s.grade
from emp e,salgrade s
where e.sal between s.losal and s.hisal and e.ename='smith'
outer joins
left outer join(只顯示左表中不匹配的記錄)
例: select e.last_name,e.department_id,d.department_id
from employees e left [outer] join departments d
on (e.department_id = d.department_id)
(把e中不匹配的顯示出來)
(oracle語法)
select e.last_name,d.department_id,d.department_id
from employees e left outer join departments d
where e.department_id = d.department_id(+)
right outer join(只顯示右表中不匹配的記錄)
select e.last_name,d.department_id,d.department_id
from employees e right [outer] join departments d
on (e.department_id = d.department_id)
(把d中不匹配的顯示出來)
(oracle語法)
select e.last_name,e.department_id,d.department_id
from employees e left outer join departments d
where e.department_id(+) = d.department_id
full outer join(左右兩個表都顯示)
select e.last_name,d.department_id,d.department_id
from employees e full [outer] join departments d
on (e.department_id = d.department_id)
cartesian product(笛卡爾集)做測試資料用;
cross join(當沒有連線條件時,或乙個無效的連線條件)
select last_name,department_name
from employees
cross join departments(輸出結果為第乙個表的行數*第二個表的行數)
Oracle表連線方式
實用記憶方法 在哪邊,哪邊就是外來鍵,該錶的資料就 少 無 那邊檢索的就是全表資料。oracle 8i,9i 表連線方法。一般的相等連線 select from a,b where a.id b.id 這個就屬於內連線。對於外連線 oracle中可以使用 來表示,9i可以使用left right f...
oracle表的連線
表連線操作有內連線和外連線兩種 1 內連線 也稱等值連線或自然連線,內連線是從結果表中刪除與其他被連線表中沒有匹配行的所有元組,所以當匹配條件不滿足時內連線可能會丟失資訊。例如 select from emp e,dept d where e.deptno d.deptno 2 外連線 外連線分為三...
oracle表連線(二)
各類連線驅動順序區別 1.巢狀迴圈連線 select leading t1 use nl t2 from t1,t2 where t1.id t2.t1 id and t1.n 19 select leading t2 use nl t1 from t1,t2 where t1.id t2.t1 i...