Jump to content

Trying to understand Joins


ebolt007

Recommended Posts

Ok, so I have a nother JOIN question, still trying to grasp it and the parenthases, the explanations I always get are so short. So here's my question,

I have 2 databases again, Users_Friends and Users_Online

inside these I need to match up the ID's in UserID and FriendID inside Users_Friends and get the other ID from those, then I need to Check to make sure the Level in that is '1' and not '0' and then Check in the Users_Online that OnlineStatus for these UID's matching with the ID's I pulled from the Users_Friends is '1' and not '0'

 

Below is what I have, and I can get all of the friends ID's correct, but can't get it to give me the OnlineStatus, I always get my OnlineStatus for each friend so it's like everyones always online. How do I get the OnlineStatus from the ID's that aren't mine from Users_Friends?

 

 
                              SELECT f.FriendID, f.UserID, f.FriendIDMAIN, f.DateRequested, o.OnlineStatus  
                              FROM Users_Friends f 
                              INNER JOIN Users_Online o ON f.FriendID = o.UserID 
                              WHERE o.OnlineStatus = '1' AND f.FriendID = '$user_ID'
                              AND f.Level = '1' 
                              UNION
                              SELECT f.FriendID, f.UserID, f.FriendIDMAIN, f.DateRequested, o.OnlineStatus  
                              FROM Users_Friends f 
                              INNER JOIN Users_Online o ON f.UserID = o.UserID 
                              WHERE o.OnlineStatus = '1' AND f.UserID = '$user_ID'
                              AND f.Level = '1'  

                              
                              ORDER BY FriendIDMAIN ASC

Link to comment
Share on other sites

Guest
This topic is now 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.