I'm working on a classes database with specific users. When a user checks off a class as complete, it is added to a "ClassUser" table with the specific classID as well as the userID that completed the class. Now what I want to do is show a list of classes that the user has NOT taken from the primary Classes table.
So far, I have this SQL statement.
This gives me a list of all classes found in the Classes table that are NOT in the ClassUser table. This is almost what I want, but now I want to add another condition so it only returns classes that userID=20 has not taken.Code:SELECT Classes.* FROM Classes LEFT JOIN ClassUser ON Classes.classID = ClassUser.classID WHERE ClassUser.classID IS NULL;
As of now this SQL statement returns the classes that all of the users haven't taken but I want to only see the classes that a specific user hasn't taken.
I've tried AND WHERE user_id=20 ,but I get no results from that.
Does anyone have any ideas?
http://imgur.com/2EA1.jpg
That is a picture of my current tables.
Once again, my goal is to display the list of classes that a specific user has not taken, where the table "ClassUser" represents the classes that a specific user has taken.
Last edited by marcuswilderby; 04-29-2009 at 01:39 AM.
Hi marcuswilderby,
Try this:
Cheers,Code:SELECT Classes.* FROM Classes LEFT JOIN ClassUser ON Classes.classID = ClassUser.classID WHERE ClassUser.userID Is Null Or ClassUser.userID<>20;
P.S. ~ Are you in the same class with jimmycantler?
Last edited by ConneXionLost; 04-29-2009 at 04:11 AM.
Docendo discimus.
Please consider:
- Thanking those who helped you. Click the reputation icon
in the contributor's post and add Reputation.
- Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks