Jump to content

Recommended Posts

Hello all,

 

I am really confused.... Here is what I have, I hope someone can help!

 

mysql 5.067

 

students table

|student_id|first_name|last_name|grade_level

 

idtrack table

id|timestamp|student_id|event_id

 

I want to select all the students that ARE NOT in the idtrack table, but in the students table, an exceptions list...essentially this:

 

|student_id|first_name|last_name|grade_level|event_id

 

...of those students with the defined grade_level and event_id

 

SELECT students.student_id, students.last_name, students.first_name, students.grade_level, idtrack.event_id
FROM students
LEFT JOIN idtrack ON students.student_id = idtrack.student_id
WHERE (students.grade_level = 11
|| idtrack.student_id IS NULL || idtrack.event_id=6)

 

every time I try the above query event_id field turns up NULL in the results.

Here is my EXPLAIN:

 

id select_type table type possible_keys key key_len ref rows Extra

1 SIMPLE students ALL NULL NULL NULL NULL 3775

1 SIMPLE idtrack ALL NULL NULL NULL NULL 6 Using where

 

Any help?

 

Thanks in advance!

Joe

 

 

Link to comment
https://forums.phpfreaks.com/topic/211849-sub-select-or-not-in-really-confused/
Share on other sites

try this

 

SELECT students.student_id, students.last_name, students.first_name, students.grade_level, idtrack.event_id
FROM students
LEFT JOIN idtrack ON students.student_id = idtrack.student_id
WHERE students.grade_level = 11
      AND ( idtrack.student_id IS NULL  OR idtrack.event_id=6)

 

this is getting all the student with grade_level 11 who, are not present in the idtrack table or those with event_id = 6

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.