Jump to content

SQL join headache


johnc71

Recommended Posts

Thanks for your help.  I tried your query but there are still issues.  If the student is enrolled in more than 1 class, lets say student #1, he will still show in query results. 

 

Also, I would like to get a list of all students who are not enrolled in the particular class, not only the ones listed in the enrollment table.  Sorry if this is confusing. 

 

Link to comment
https://forums.phpfreaks.com/topic/155445-sql-join-headache/#findComment-818120
Share on other sites

I could not modify the post above so I am posting this as edit to make it more clear.

 

If I ran the following:

SELECT s.name FROM students s LEFT JOIN enrollment e ON s.student_id = e.student_id WHERE e.class_id != 2

 

I get the following results:

 

Mary

Terry

John

Mark

 

Isues:

Terry should not be listed. 

 

Also, Stephanie, James and Irena should be listed.  Hope this is more clear.

Link to comment
https://forums.phpfreaks.com/topic/155445-sql-join-headache/#findComment-818129
Share on other sites

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.