Simple SQL query problem, can anyone help?
Posted 03 June 2006 - 10:17 PM
The database contains a table of subjects, and also a table of subjects that users have enrolled in.
I need a query that returns a list of subjects that the user has not enrolled in.
Subject table: subject_id, name
Subject_Enrolled table: enrollment_id, subject_id, user_id
So I have to return all names in the subject table unless the particular user already has an entry for the
subject in the subject_enrolled table. What is the best way to get the query that returns the names of
all the subjects that the user has not yet enrolled in?
Thanks in advance!
Posted 03 June 2006 - 10:48 PM
SELECT s.name FROM Subject AS s LEFT JOIN Subject_Enrolled AS se USING ( subject_id ) WHERE user_id = '<your user id>' AND se.subject_id IS NULL
Hope that helps.
Posted 03 June 2006 - 11:03 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users