kreut Posted February 21, 2011 Share Posted February 21, 2011 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 More sharing options...
requinix Posted February 21, 2011 Share Posted February 21, 2011 What are your table structures? And if a question is not assigned, does it have an entry in the assignments_questions table (with some field as NULL, maybe)? Link to comment https://forums.phpfreaks.com/topic/228424-not-including-some-items-in-a-query/#findComment-1177797 Share on other sites More sharing options...
kreut Posted February 21, 2011 Author Share Posted February 21, 2011 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 https://forums.phpfreaks.com/topic/228424-not-including-some-items-in-a-query/#findComment-1177812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.