Hi Everyone,
I'm trying to perform a query on some responses I have stored. I want to be
able to add up a score (using SUM() ) but first checking that all the
questions have been answered.
I've tried
SELECT *
FROM `questions`
LEFT JOIN `responses`
ON `questions`.`qid` = `responses`.`qid`
AND `responses`.`yearid` = 1 AND `responses`.`uid` = 1
WHERE `value` = NULL OR '-1'
ORDER BY value DESC
but it only returns all the rows even if value is '1' those question
a entry for a question is created with a `value` value of -1 when it is
accessed.
In short, I need to be able to identify those question which either don't
have an entry in `responses` for them or have an entry set to `-1`
RESPONSES
+-------+---------+
| Field | Type |
+-------+---------+
| uid | int(11) |
| yearid | int(11) |
| qid | int(11) |
| value | int(1) |
+-------+---------+
QUESTIONS
+----------+--------------+
| Field | Type |
+----------+--------------+
| qid | int(11) |
| qtext | varchar(100) |
+----------+--------------+
This is really bugging me. I can seem to make sense of it in my head, but
not able to translate it to SQL
Hope someone can help,
Cheers,
Greg