NOT IN query
Posted on 2004-04-14
A student takes one Program. The Program ID is in the Students table.
We have a table that assigns courses to a program.
A Program can have many courses.
We also have a table that assigns courses to a student(Course ID and Student ID), the courses that are assigned are limited to only the courses that are assigned to the Program that the student is taking.
We are constructing 2 queries, one to show all the courses that a student is taking. This is easy and is working.
The next query to show the list of course that the student is YET to take which belongs to the Program he is taking.
We have an sql statement but there are errors round about the NOT IN syntax.
SELECT programcourses.courseid FROM programcourses WHERE programcourses.programid = ('$programid') AND programcourses.courseid NOT IN(SELECT studentcourses.courseid FROM studentcourses WHERE studentid='".$_GET['id']."')