Reputation: 1160
How do I return a 0 with as Responses with the PossibleAnswerText if count is 0? Right now it won't return anything.
select
COUNT(sr.Id) AS 'Responses', qpa.PossibleAnswerText
from
CaresPlusParticipantSurvey.QuestionPossibleAnswer as qpa
join
CaresPlusParticipantSurvey.SurveyResponse as sr on sr.QuestionPossibleAnswerId = qpa.Id
where
sr.QuestionPossibleAnswerId = 116
GROUP BY
qpa.PossibleAnswerText
Upvotes: 0
Views: 167
Reputation: 181077
You'll need to use LEFT JOIN
, and remove the condition on the "rightmost" table from the WHERE
clause;
SELECT COUNT(sr.Id) AS 'Responses', qpa.PossibleAnswerText
FROM CaresPlusParticipantSurvey.QuestionPossibleAnswer AS qpa
LEFT JOIN CaresPlusParticipantSurvey.SurveyResponse as sr
ON sr.QuestionPossibleAnswerId = qpa.Id
WHERE qpa.Id = 116
GROUP BY qpa.PossibleAnswerText
Upvotes: 1