一個是普通的聯接,結果中的記錄在兩個表中都有。
一個是左外聯接,結果中的記錄在A表中存在,B表中不一定有。相當於a表為主體表,b為輔助表。
例子:
mysql> select * from a;
+------+------+
| id | col |
+------+------+
| 1 | 11 |
| 2 | 12 |
| 3 | 13 |
+------+------+
3 rows in set (0.00 sec)
mysql> select * from b;
+------+------+
| id | col |
+------+------+
| 2 | 22 |
| 3 | 23 |
| 5 | 25 |
+------+------+
3 rows in set (0.00 sec)
mysql>
mysql> select * from a,b where a.id=b.id;
+------+------+------+------+
| id | col | id1 | col1 |
+------+------+------+------+
| 2 | 12 | 2 | 22 |
| 3 | 13 | 3 | 23 |
+------+------+------+------+
2 rows in set (0.08 sec)
mysql> select * from a left join b on a.id=b.id;
+------+------+------+------+
| id | col | id1 | col1 |
+------+------+------+------+
| 1 | 11 | NULL | NULL |
| 2 | 12 | 2 | 22 |
| 3 | 13 | 3 | 23 |
+------+------+------+------+
3 rows in set (0.00 sec)
mysql>
