2010年9月28日 星期二

多資料表查詢,利用 LEFT JOIN

如果你想透過 MySQL 一次查詢多筆資料表資料,可以使用 LEFT JOIN 的方式達成

SELECT a.id,a.title,b.date FROM table1 AS a LEFT JOIN table2 AS b ON a.id=b.id;

LEFT JOIN 左邊是主要資料表,換句話說 table1 必須有資料才能查詢