The easiest way to explain this will be to draw out the two tables for you guys – so here it goes..
sl_project_course project_id | course_id 50 1 sl_course professor_id | course_id | course_name 1 1 "history" 1 2 "law" 1 3 "art" 1 2 "law"
Information I already have
- Project_id = 50
- Professor_id = 1
What I want:
I want all of the course_id’s that the professor is teaching, where
the course_id is not affiliated with the project at hand (in this case
the project at hand is1– as shown above.
So, the data I want to come back from the query is:
2 "law" 3 "art"
** My attempt:**
$sql_course_not_in_project = "SELECT C.course_id, C.course_subject
FROM sl_course C
LEFT OUTER JOIN sl_project_course PC on PC.project_id = 50
WHERE C.course_id <> PC.course_id AND C.professor_id = 1";
This works, except when there are two rows in sl_project_course the query no longer works correctly.
I appreciate any help!
Thanks,
Evan
1 Answer