天天看點

Idea資料庫操作(Full Join)

Join全外連接配接(Full Outer)概述:

隻要其中某個表存在比對,FULL JOIN 關鍵字就會傳回行。

可尴尬的是,MySQL并不支援Full Join。

不過依然有辦法解決。詳細請繼續往下看。

1、首先,你還是要有兩個表:

表1:people

表2:students

Idea資料庫操作(Full Join)
Idea資料庫操作(Full Join)

2、然後,進行SQL語句操作

SELECT students.s_name,students.s_age,people.p_sex
FROM students
LEFT JOIN people
ON students.s_name=people.p_name
UNION ALL
SELECT students.s_name,students.s_age,people.p_sex
FROM students
RIGHT JOIN people
ON students.s_name=people.p_name

           

即:

左外連接配接+右外連接配接+UNION ALL=FULL JOIN。

哈哈哈,驚不驚喜!意不意外!

3、結果如下:

Idea資料庫操作(Full Join)

Idea連接配接資料庫(MySql Workbench)

Idea資料庫操作(Inner Join)

Idea資料庫操作(Left Join)

Idea資料庫操作(Right Join)