I'm really struggling here to do this. I've looked online but I just don't understand what other people are doing and how it would work for my situation.
I have a questions table with questions (Columns: question_id, question, answer1, answer2, questioner_id), then I have a table (questions_answered) with rows of who answered what question. (Columns: user_id and question_id)
I need to grab questions for the user but make sure that I don't pick questions that the user has already answered by comparing the user_id and question_id.
I'm racking my head over how to do this. I've tried to do two sets of queries and comparing the arrays to no avail.
I'm now trying to do it in 1 query but I'm just so unsure of how.
Please may anyone help me?
If you need any more information just say
Kindest Regards
Try this with subquery
SELECT * FROM questions q
WHERE q.question_id NOT IN
(SELECT qa.question_id FROM questions_answered qa WHERE qa.user_id ='1')
or use NOT EXISTS
SELECT * FROM questions q
WHERE NOT EXISTS
(SELECT * FROM questions_answered qa WHERE qa.user_id ='1')
or
SELECT * FROM questions q
WHERE NOT EXISTS
(SELECT * FROM questions_answered qa WHERE qa.question_id =q.question_id AND qa.user_id ='1')