Hey Everyone, I am having an issues getting results from a JOINED table, any help would be greatly appreciated. I have 2 tables, and I need to grab results where a user has NOT answered a question: questions (table) ------------------------------ | question_id | active | ------------------------------ | 123456 | 1 | ------------------------------ | 123457 | 1 | ------------------------------ | 123458 | 1 | ------------------------------ results (table) ------------------------------ | question_id | user_id | ------------------------------ | 123456 | 45 | ------------------------------ | 123457 | 23 | ------------------------------ | 123456 | 23 | ------------------------------ I want to grab questions that a certain user has NOT answered. In the example above user_id 23 has answered question_id 123456 & 123457 - they have not answered 123458. Here's my current code, but it's not working and I don't know why?? SELECT questions.question_id FROM questions LEFT JOIN results ON (questions.question_id = results.question_id) WHERE questions.active = '1' AND results.user_id != 'USERID' OR results.user_id IS NULL GROUP BY questions.question_id ORDER BY questions.question_id DESC
So, what results is your code producing that you do NOT want? Kind of hard to debug something if we do not have a place to start.
That's what's odd, it looks correct, but once a user answers a question it just spits out the exact same question again. They are only suppose to answer each question 1 time.
It looks like when another user answer the same question it assumes that since it's joined and that user's ID is not the same or not NULL, it pops the question back up again - which is why the question just keeps coming back up over and over again. I need something that checks the question for a users response and then gets the next question.