SQL FULL JOIN 全部外部連接
FULL JOIN 即為 LEFT JOIN 與RIGHT JOIN 的聯集,它會返回左右資料表中所有的紀錄,不論是否符合連接條件
SELECT C.CustomerName, O.Order_No FROM table_A as C FULL JOIN table_ as O ON C.CustomerID=O.CustomerID;
CustomerID |
CompanyName |
CustomerName |
Address |
City |
PostalCode |
Country |
1 |
Alfreds Futterkiste |
Maria Anders |
Obere Str. 57 |
Berlin |
12209 |
Germany |
21 |
Ana Trujillo Emparedados y helados |
Ana Trujillo |
Avda. de la Constitucion 2222 |
Mexico D.F. |
05021 |
Mexico |
31 |
Antonio Moreno Taqueria |
Antonio Moreno |
Mataderos 2312 |
Mexico D.F. |
05023 |
Mexico |
OrderID |
CustomerID |
OrderDate |
1001 |
1 |
1999-10-10 |
1002 |
2 |
1999-11-11 |
1003 |
3 |
1999-12-12 |
1004 |
1 |
1999-12-12 |
1005 |
31 |
1999-12-12 |
1006 |
31 |
2000-01-01 |
結果:
CustomerName |
OrderID |
Maria Anders |
1001 |
|
1002 |
|
1003 |
Maria Anders |
1004 |
Antonio Moreno |
1005 |
Antonio Moreno |
1006 |
Ana Trujillo |
|