Reputation: 57
SELECT COUNT(*) totalStudent,
c.*
FROM classroom c
INNER JOIN student s
ON c.classID = s.classID
GROUP BY c.classID
How to get zero in totalStudent
? if student empty inside the classroom.
Upvotes: 0
Views: 280
Reputation: 1270401
I am interpreting your question as: "Some classes have no students. How do I include these?" If this is correct, then the key is left join
:
SELECT c.classId, COUNT(s.classId)
FROM classroom c LEFT JOIN
student s
ON c.classid = s.classid
GROUP BY c.classId;
Upvotes: 1