MySQL左连接不同于简单连接。MySQL LEFT JOIN提供该表额外字段在左侧。
如果使用LEFT JOIN,得到的所有记录的匹配方式相同,
在左边表中得到的每个记录不匹配也会有一个额外的记录。
从而确保(在本例子),每次作者信息都会列出:
SELECT * from tutorials_tbl;
+-------------+----------------+-----------------+-----------------+
| tutorial_id | tutorial_title | tutorial_author | submission_date |
+-------------+----------------+-----------------+-----------------+
|
|
|
+-------------+----------------+-----------------+-----------------+
mysql> SELECT * FROM tcount_tbl;
+-----------------+----------------+
| tutorial_author | tutorial_count |
+-----------------+----------------+
|
| mahnaz | NULL |
| Jen | NULL |
|
|
|
+-----------------+----------------+
mysql> SELECT a.tutorial_id, a.tutorial_author, b.tutorial_count
-> FROM tutorials_tbl a LEFT JOIN tcount_tbl b
-> ON a.tutorial_author = b.tutorial_author;
+-------------+-----------------+----------------+
| tutorial_id | tutorial_author | tutorial_count |
+-------------+-----------------+----------------+
|
| Abdul S | NULL |
|
+-------------+-----------------+----------------+
rows in set (0.02 sec)