Jump to content

Not including some items in a query


kreut

Recommended Posts

Hello,

 

I was hoping that someone can finish helping me write a query.  I'm trying to select all questions from a database and then whittle it down to :

 

1) questions written by a particular user (that's my first WHERE clause below)

2) that have not yet been assigned by a particular user.  My AND statement just checks at the assignment level.

3) This is the part I'm missing:  In "English" I need AND :  questions.question_id FOR THAT PARTICULAR $user_id doesn't equal ANY of the questions (given by assignments_questions.question_id) in assignments_questions FOR THAT PARTICULAR $user_id.

 

Any help to finish the query would be appreciated!

 

Thank you.

 

FROM questions,assignments_questions
		USING (question_id)
		WHERE questions.user_id = $user_id 
		AND questions.question_id <> assignments_questions.question_id

Link to comment
https://forums.phpfreaks.com/topic/228424-not-including-some-items-in-a-query/
Share on other sites

Thank you for the quick response...

 

In my questions table I have (you can create a new question without yet putting it to an assignment):

  question_id  (index)

  user_id  (the user_id is the person who wrote it)

 

In my assignments table I have all of the assignments for a given course:

  course_id (index)

  assignment_id  ---once you create a course, you can create an assignment (with or without questions).  Once you add    the first question to an assignment, it will appear on the assignments_questions table

 

In my assignments_questions, you can create a new assignment :

  assignment_id  (index)

question_id (once an assignment is created, questions can be added to it)

 

If a question hasn't been assigned, it doesn't yet exist in the assignments_questions table.

 

Please let me know if there's anything else that I can clear up...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.