Jump to content

Noobie stuff!!!


ToonMariner

Recommended Posts

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

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

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_users

course_id  user_id 
1          1
2          1
5          1
3          2

courses

course_id  course_name
1          First Aid
2          Fire Fighting
3          Manual Handling
4          Tea Making
5          Walking Straight
6          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

[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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.