一、表間關聯基礎
1.關聯的實現
2.從表(子表)
3.主表(父表)
4.主鍵表達一方,外鍵表達多方
二、關聯查詢
1.概念:
2.關聯查詢分類:
3.關聯實現方式:
三、內關聯查詢
1.Inner join :
2.實現方式
2.1 oracle方式:
select *
from tablea, tableb
where --條件
PS:關聯時,重複的列必須指明select dept.deptno, empno
from emp, dept
where emp.deptno = dept.deptno
2.2 標準方式:
select ...
from table1 [inner] join table2
on table1.columns = table2.columns
PS:這兩種方式,字段可以不同
2.3 使用using關聯
select ...
from table1 [inner] join table2
using columns
PS:要求關聯字段必須用一樣
2.4 使用自然連接
只能用於內聯
select ...
from table1 natural join table2
四、外關聯查詢
1. Outer join:
2.左外關聯查詢
2.1 oracle方式
select ...
from tableleft, tableright
where tableleft.columns = tableright.columns(+)
2.2 標準SQL
select ...
from tableleft left outer join tableright
on tableleft.columns = tableright.columns
2.3 一樣字段可以使用using
3.右關聯查詢
3.1 oracle方式
select ...
from tableleft, tableright
where tableleft.columns(+) = tableright.columns
3.2 標準SQL
select ...
from tableleft right [outer] join tableright
on tableleft.columns = tableright.columns
3.3 使用using
4.全外聯查詢
4.1 oracle
4.2 標準SQL
select ...
from tableleft full outer join tableright
on tableleft.columns = tableright.columns
五、交差聯接
1.cross join:
2.實現方式
2.1 oracle 方式
select ...
from tableleft, tableright
-- 無條件
2.2 標準SQL
select ...
from tableleft cross join tableright
六、自關聯
1.self join:
2.實現方式:
select ...
from tablea, tableb
七、彙總查詢
1.彙總函數
2.分類彙總語句
group by table.columns
2.2 對彙總後記錄進行篩選