So I have these tables:
STUDENTS:
Student ID – First name – Last name – Email
COURSES:
Catalog ID – Course Name – Description
TERMS:
Term ID – Start Date – End Date
COURSEINSTANCES:
CourseInstance ID – Catalog ID – Term ID
STUDENTCOURSES:
StudentCourse ID – CourseInstance ID – Student ID – Date added to database
This makes it easy to see which students have taken which courses. I’m not sure how to go about finding out which students have NOT taken a particular course.
Doing something like this:
WHERE ((CourseInstances.CatalogLookup)<>504)
will just give me a list of courses taken by students that do not equal catalog number 504 like this:
Tara – 501
Tara – 502
Tara – 505
John – 503
So for example I’ve taken 504. Therefore I do not want me to show up on this list. The SQL above will just show all of my courses that are not 504, but it will not exclude me from the list.
Any ideas? Is this possible?
I prefer this syntax over outer joins, IMO it’s easier to read:
In the nested query, you select the StudentIDs of all students who HAVE taken course 504.
Then, you select all the students whose StudentIDs are not included in the nested query.
EDIT:
As ChrisJ already said, the c and the s are aliases for the table names.
Without them, the query would look like this:
I always use aliases because:
a) I’m too lazy to type the table names more often than necessary.
b) In my opinion it’s easier to read, especially when you join tables with long names.