I have two tables:
question
question_id | question
question_answer
answer_id | question_id | choice_id | user_id | explain
I want to get all questions for which particular user haven’t answered yet.
SELECT question, question_id as questionId
FROM question q
LEFT JOIN question_answer qa USING(question_id)
WHERE qa.user_id!=$userId
I get in this case zero rows. I tried also
SELECT question, q.question_id as questionId
FROM question q
LEFT JOIN question_answer qa ON q.question_id=qa.question_id AND qa.user_id!=$userId
Obviously this returns all records. I stuck here how to make this query.
The part of your
LEFT JOINwhere you check for a specific user should be reversed, i.e.user_id = $userIdinstead ofuser_id <> $userId.From the resulting rows you select the ones where
user_id IS NULLto find the questions for which$userIdhas not answered (yet).