LEFT JOIN 关键字从左表(table1)返回所有的行,即使右表(table2)中没有匹配。如果右表中没有匹配,则结果为 NULL。
SQL LEFT JOIN 语法:
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;
示例:
SELECT student.StudentId,student.StudentName,student_class.ClassID
FROM student
LEFT JOIN student_class
ON student.StudentId = student_class.StudentID
ORDER BY student.StudentId DESC;
LEFT JOIN 关键字从左表(Websites)返回所有的行,即使右表(access_log)中没有匹配。