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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.