Przenieś teacher_students.teacher_id = 1
sprawdź z WHERE
klauzula dołączania ON
klauzula.
Gdy warunek, który odnosi się do tabeli po prawej stronie LEFT JOIN
jest umieszczony w klauzuli WHERE, LEFT JOIN jest anulowany i działa jako 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