SQL--左外连接(LEFT JOIN)

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)中没有匹配。

猜你喜欢

转载自blog.csdn.net/LoveRestart/article/details/81608953