How can i do this via MySQL plz? [SOLVED]

Hello

I’m working to create a quiz website. But i have a problem with (How to denied the viewed questions for a member).

Let’s me explain it:

I’ve 3 table in my database.

  • The first table called “members” to store the members details like memberID, memberName, etc…

  • The second table called “denied_questions” is stored the answered questions and it’s contains two field (qustionID, memberID).

  • The third table called “questions” is contains the questions list.

Now. I want to get a random question from questions table. The question should not be viewed to the member in the past.

The following SQL does not working!


SELECT
    qus.qusID,
    qus.question
FROM
    `questions` AS qus,
    `denied_qus` AS denied
WHERE
    denied.memberID != 3 AND qus.qusID != denied.qusID 

ORDER BY RAND()

I just want to get a random question from the questions table and compare this question with the answered questions from the “denied_questions”
table.

Any idea please?

Wow great! we can do it via Outer Joins!
Thank you “r937
Let me to read something about OUTER JOINS :smiley:

welcome to left outer joins :slight_smile:

SELECT qus.qusID
     , qus.question
  FROM questions AS qus
LEFT OUTER
  JOIN denied_qus AS denied
    ON denied.qusID = qus.qusID
   AND denied.memberID = 3
 WHERE denied.qusID IS NULL
ORDER 
    BY RAND() LIMIT 1