I have 2 tables and want to add the count column from the bottom table to the top table (join on “OID” and “OPTID”) and if no count is found set the cell to zero. How can I do this?
SELECT questions.pollid, questions.id, questions.title,
questions.ordering, options.oid,
options.qoption, options.ordering FROM questions, options WHERE
(questions.pollid = 2 AND
questions.type = 1 AND
questions.ordering = 1) AND
(questions.id = options.quid)
pollid id title ordering Oid qoption ordering
2 4 Overall customer experience 1 10 Excellent 1
2 4 Overall customer experience 1 11 Very good 2
2 4 Overall customer experience 1 12 Average 3
2 4 Overall customer experience 1 13 Poor 4
2 4 Overall customer experience 1 14 Terrible 5
SELECT count(*), optid FROM poll_data WHERE block = 0 GROUP BY optid;
count( * ) optid
2 4
2 11
1 12
1 13
1 14
2 16
1 18
1 19