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
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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.