Page 1 of 1

OMG I'm going crazy. Multiple Join Help!

Posted: Thu Jun 10, 2010 3:22 pm
by Pryme
I've been trying to figure this out for days. Can someone help me???

Ok, so a user logs in creating a $_SESSION['userName']. This user has the ability to sign up for an event from a list of events. The problem I'm having is I need the user to only be presented with the events he HASN'T signed up for yet.

3 Tables: Users(Primary Key=userName), Events(Primary Key=eventID), and UsersEvents(Keys=userName and eventID).

So I need to come up with a sql statement along the lines of "SELECT eventIDs that's not associated with $_SESSION['userName'] in the UsersEvents table"

This is what I've tried:

"SELECT Events.eventID, UsersEvents.eventID FROM Events, UsersEvents WHERE UsersEvents.eventID != Events.eventID AND UsersEvents.userName != '".$_SESSION['userName']."'"

It's does not work. I'm not very experienced with joins.

Any help would be freakin awesome.

Re: OMG I'm going crazy. Multiple Join Help!

Posted: Thu Jun 10, 2010 3:53 pm
by Eran
Negative left join -

Code: Select all

$query = "SELECT Events.eventID FROM Events
LEFT JOIN UsersEvents ON UsersEvents.eventID = Events.eventID AND UsersEvents.userName = '".$_SESSION['userName'] . "' 
WHERE UsersEvents.eventID IS NULL";

Re: OMG I'm going crazy. Multiple Join Help!

Posted: Thu Jun 10, 2010 5:41 pm
by Pryme
Thanks for the response! I'll have to wait till I go into work tomorrow to see if this work but I thank you anyways.