数据库中学生表和课程表如下:

Sql server中左连接语句-LMLPHP

Sql server中左连接语句-LMLPHP

左连接sql语句:

select a.studentName,a.studentAge,b.courseName
from student a left join course b //left join 左连接,以左表为主
on a.studentID=b.studentID

查询结果如下:

Sql server中左连接语句-LMLPHP

查询的结果是以左表student为主,student对应的studentID在右表course如果不存在的话,就会用NULL值来代替。

04-28 11:54