Flyt teacher_students.teacher_id = 1
tjek fra WHERE
klausul til sammenføjningen ON
klausul.
Når en betingelse, der refererer til en tabel i højre side af en LEFT JOIN
er sat i WHERE-sætningen, annulleres LEFT JOIN, og den fungerer som en 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