So I've been going at this a good few hours now with no luck, not a DB expert so thought someone may be able to help here?
Essentially I have a database consisting of questions, matching answers, users, and user groups.
I'm trying to select all questions where a user in each of the team's hasn't yet got a record in the answers table.
E.g. if a group 1 user has answered question 2, it won't be selected for any other user in that group.
Here's my attempt so far:
SELECT q.*
FROM questions q
LEFT JOIN answers a ON q.id = a.question
#LEFT OUTER JOIN answers a ON q.id = a.question
LEFT JOIN people p ON a.user = p.id
LEFT JOIN groups g ON p.group = g.id
WHERE
q.category = 'food'
AND
g.id = (SELECT group FROM people WHERE id = 1)
AND
a.id IS NULL;
I'm guessing it's an issue with how I'm joining the people and groups, though not entirely sure.