MySQL左连接:
一个简单的连接和一个MySQL左连接是不同的。一个MySQL LEFT JOIN提供了额外的考虑到在左边的表。
如果做了LEFT JOIN,得到的所有记录以同样的方式相匹配,此外,得到一个额外的记录每个不匹配的记录,在左表中的联接 - 从而保证了每一个作者得到关联(本例子中):
实例:
试试下面的例子就明白了LEFT JOIN:
| root@host# mysql -u root -p password; Enter password:******* mysql> use TUTORIALS; Database changed 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 | +-------------+-----------------+----------------+ | 1 | John Poul | 1 | | 2 | Abdul S | NULL | | 3 | Sanjay | 1 | +-------------+-----------------+----------------+ 3 rows in set (0.02 sec) |
需要做更多的实践才能熟悉JOINS。这是一个复杂的概念,在MySQL/SQL将变得更加清晰。










