ToonMariner Posted November 7, 2006 Share Posted November 7, 2006 God i don't know why I can't get this.Got two tables one table (courses) contains information on trainingwith an id field of 'course_id'.The other table (course_users) has just two fields 'course_id' and 'user_id'.I want to select all the records from courses that don't exist in course_users BUT only where 'user_id' is equal to a seesion var used to id them. tried all manner of left joins but to no avail.Any help appreciated. Link to comment https://forums.phpfreaks.com/topic/26513-noobie-stuff/ Share on other sites More sharing options...
btherl Posted November 8, 2006 Share Posted November 8, 2006 That doesn't make sense.. if the entry isn't in course_users, then there is no user_id.Or do you mean entries which either aren't in course_users, or are in course_users but don't match the user_id? With the intention being of finding all courses that a user is not currently associated with? Link to comment https://forums.phpfreaks.com/topic/26513-noobie-stuff/#findComment-121434 Share on other sites More sharing options...
ToonMariner Posted November 8, 2006 Author Share Posted November 8, 2006 Course_users will have many entries from many users. I want to select the id of the course that user X has NOT done.so course_user will contain several records with user_id = x. I want to grab those records and then select ALL teh courses in the other table that are NOt in the course_id field of course_users.eg[tt]course_userscourse_id user_id 1 12 15 13 2coursescourse_id course_name1 First Aid2 Fire Fighting3 Manual Handling4 Tea Making5 Walking Straight6 Driving[/tt]If User 1 cam along I woudl want the query to return courses 3,4 and 6 if user 2 came along I would want to return courses 1,2,4,5 and 6.Hope that makes sense... Link to comment https://forums.phpfreaks.com/topic/26513-noobie-stuff/#findComment-121539 Share on other sites More sharing options...
Zane Posted November 8, 2006 Share Posted November 8, 2006 [quote]I want to select all the records from courses that don't exist in course_users BUT only where 'user_id' is equal to a seesion var used to id them.[/quote][code]SELECT courses.course_id FROM courses INNER JOIN course_users ON courses.course_id != course_users.course_id WHERE user_id = "whatever"[/code]give that a try... Link to comment https://forums.phpfreaks.com/topic/26513-noobie-stuff/#findComment-121551 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.