MySQL left join 與 join 有所不同。 MySQL LEFT JOIN 會讀取左邊數(shù)據(jù)表的全部數(shù)據(jù),即便右邊表無對應(yīng)數(shù)據(jù)。
嘗試以下實例,理解MySQL LEFT JOIN的應(yīng)用:
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)
以上實例中使用了LEFT JOIN,該語句會讀取左邊的數(shù)據(jù)表tutorials_tbl的所有選取的字段數(shù)據(jù),即便在右側(cè)表tcount_tbl中沒有對應(yīng)的tutorial_author字段值。
2015職稱計算機考試書PowerPoint2007中 .. 定價:¥45 優(yōu)惠價:¥42 更多書籍 | |
2015年全國職稱計算機考試教材(2007模 .. 定價:¥225 優(yōu)惠價:¥213 更多書籍 |