LEFT JOIN 关键字从左表(table1)返回所有的行,即使右表(table2)中没有匹配。如果右表中没有匹配,则结果为 NULL。
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
以上一篇的student和class表为例
SELECT student.stuid,class.classname,student.name FROM student LEFT JOIN class ON student.name=class.classteacher;
SELECT student.stuid,class.classname,student.name FROM class LEFT JOIN student ON student.name=class.classteacher;