Di chuyển teacher_students.teacher_id = 1 kiểm tra từ WHERE mệnh đề tham gia ON mệnh đề.
Khi một điều kiện tham chiếu đến một bảng ở phía bên phải của LEFT JOIN được đặt trong mệnh đề WHERE, LEFT JOIN bị hủy và nó hoạt động như một INNER JOIN .
SELECT count(teacher_students.student_id) AS rcount <--- changed
, questions.id
FROM "questions"
LEFT JOIN answers
ON answers.question_id = questions.id
LEFT JOIN teacher_students
ON teacher_students.student_id = answers.student_id
AND teacher_students.teacher_id = 1
WHERE questions.test_id = 1
GROUP BY questions.id
ORDER BY questions.id