LEFT JOIN(或 LEFT OUTER JOIN)回傳左表(table1)所有資料列,並嘗試依 ON 條件比對右表(table2)。左表每一列都會出現在結果中;若右表無對應資料,右表欄位顯示 NULL。這是最常用的外部聯結方式。
SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
等同寫法:
SELECT column_name(s) FROM table1 LEFT OUTER JOIN table2 ON table1.column_name = table2.column_name;

+----+--------------+---------------------------+-------+---------+ | id | name | url | alexa | country | +----+--------------+---------------------------+-------+---------+ | 1 | Google | https://www.google.cm/ | 1 | USA | | 2 | 淘寶 | https://www.taobao.com/ | 13 | CN | | 3 | 菜鳥教程 | https://www.runoob.com/ | 4689 | CN | | 4 | 微博 | https://weibo.com/ | 20 | CN | | 5 | Facebook | https://www.facebook.com/ | 3 | USA | | 7 | stackoverflow| https://stackoverflow.com/ | 0 | IND | +----+--------------+---------------------------+-------+---------+
+-----+---------+-------+------------+ | aid | site_id | count | date | +-----+---------+-------+------------+ | 1 | 1 | 45 | 2016-05-10 | | 2 | 3 | 100 | 2016-05-13 | | 3 | 1 | 230 | 2016-05-14 | | 4 | 2 | 10 | 2016-05-14 | | 5 | 5 | 205 | 2016-05-14 | | 6 | 4 | 13 | 2016-05-15 | | 7 | 3 | 220 | 2016-05-15 | | 8 | 5 | 545 | 2016-05-16 | | 9 | 3 | 201 | 2016-05-17 | +-----+---------+-------+------------+
以 Websites 為左表,access_log 為右表,查詢所有網站及其訪問記錄:
SELECT Websites.name, access_log.count, access_log.date FROM Websites LEFT JOIN access_log ON Websites.id = access_log.site_id ORDER BY access_log.count DESC;
輸出結果:

結果解析:
SELECT Websites.name FROM Websites LEFT JOIN access_log ON Websites.id = access_log.site_id WHERE access_log.site_id IS NULL;
可找出從未被訪問的網站。
SELECT Websites.name, COUNT(access_log.aid) AS visit_times FROM Websites LEFT JOIN access_log ON Websites.id = access_log.site_id GROUP BY Websites.name ORDER BY visit_times DESC;
即使無訪問記錄,COUNT 會回傳 0 而非 NULL。
ON 條件欄位有索引(如 Websites.id、access_log.site_id)。ON 條件中使用函數運算,導致索引失效。