修改查询?

时间:2012-08-20 03:05:02

标签: mysql

我想向所有学生展示即使他们没有注册课程。我如何修改此查询以显示null?

SELECT a.lastname,
       Count(c.credits) TotalCredits
FROM   students a
       INNER JOIN registration b
               ON a.studentid = b.studentid
       INNER JOIN courses c
               ON b.courseid = c.coursenumber
GROUP  BY a.studentid

查询由John Woo完成

1 个答案:

答案 0 :(得分:1)

使用LEFT代替INNER

SELECT a.lastname,
       Count(c.credits) TotalCredits
FROM   students a
       LEFT JOIN registration b
              ON a.studentid = b.studentid
       LEFT JOIN courses c
              ON b.courseid = c.coursenumber
GROUP  BY a.studentid