How can I get the count is 0 if it is null. when I run with the following statement:
SELECT S.shortText, COUNT(O.selectionID) AS C FROM Opinions O
LEFT JOIN Selections S ON S.id=O.selectionID
WHERE S.qID=3 AND MONTH(O.entryDate)=5
GROUP BY S.shortText
shortText C
---------------- ----
Leisure 0 <------ this line missing
Business 3
University visit 1
My Selections Table
id shortText
----- ----------------
1 Leisure
2 Business
3 University visit
My Opinions Table
id entryDate selectionID
----- --------------------- --------------
186 5/21/2012 11:34:37 AM 2
205 5/22/2012 9:13:25 AM 2
216 5/22/2012 9:43:14 AM 2
237 5/24/2012 8:24:00 PM 3
If you want to display the Leisure rows as 0 even there is no matching record in opinions table. Use subquery as below:
http://sqlfiddle.com/#!2/8ca3e/11