我自己雖然對DB與SQL也並不是說很強的狀況,但我還是懂甚麼是JOIN(其實是在實習時懂得)但是要我解釋我還真不太會形容
左邊的表
PK | FK |
1 | a1 |
2 | a2 |
3 | a3 |
右邊的表
PK | Description |
a2 | a2很棒 |
a3 | a3很棒 |
a4 | a4很棒 |
Inner join
簡單來說就是 左邊的表 與右邊的表 都要相等才會帶出資料
Select * from table1, table2
Where table1.FK=table2.PK
Where table1.FK=table2.PK
Left join
是以左邊為主 左邊的表資料全部留下,右邊的表有符合就一起帶入
表一所有資料都要帶出,並且帶出有符合的表二資料
Select * from table1
Left outer join table2 on table1.FK = table2.PK
Left outer join table2 on table1.FK = table2.PK
Right join
是以右邊為主 右邊的表資料全部留下,左邊的表有符合就一起帶入表二所有資料都要帶出,並且帶出有符合的表一資料
Select * from table1
Right outer join table2 on table1.FK = table2.PK