只要其中某個表存在匹配,FULL JOIN 關鍵字就會返回行。數據庫
SELECT column_name(s) FROM table_name FULL JOIN table_name
ON table_name.column_name=table_name.column_name and table_name.column_name=table_name.column_name and...
FULL JOIN table_name
ON table_name.column_name=table_name.column_name and table_name.column_name=table_name.column_name and...
...
WHERE table_name.column_name = ? and table_name.column_name = ? and....
ORDER BY table_name.column_name, table_name.column_name
註釋:在某些數據庫中, FULL JOIN 稱爲 FULL OUTER JOIN。spa
"Persons" 表:ci
Id_P | LastName | FirstName | Address | City |
---|---|---|---|---|
1 | Adams | John | Oxford Street | London |
2 | Bush | George | Fifth Avenue | New York |
3 | Carter | Thomas | Changan Street | Beijing |
"Orders" 表:it
Id_O | OrderNo | Id_P |
---|---|---|
1 | 77895 | 3 |
2 | 44678 | 3 |
3 | 22456 | 1 |
4 | 24562 | 1 |
5 | 34764 | 65 |
如今,咱們但願列出全部的人,以及他們的定單,以及全部的定單,以及定購它們的人。table
您能夠使用下面的 SELECT 語句:ast
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons FULL JOIN Orders ON Persons.Id_P=Orders.Id_P ORDER BY Persons.LastName
結果集:語法
LastName | FirstName | OrderNo |
---|---|---|
Adams | John | 22456 |
Adams | John | 24562 |
Carter | Thomas | 77895 |
Carter | Thomas | 44678 |
Bush | George |
|
|
|
34764 |
FULL JOIN 關鍵字會從左表 (Persons) 和右表 (Orders) 那裏返回全部的行。若是 "Persons" 中的行在表 "Orders" 中沒有匹配,或者若是 "Orders" 中的行在表 "Persons" 中沒有匹配,這些行一樣會列出。數據