Coly010 Posted January 6, 2014 Share Posted January 6, 2014 I'm a bit confused on what type of JOIN to use for this. I have three tables, all containing the column USERID. I want to join them all together into one query so that i can place them into an array. Right so i want the row from the tables as long as the userid is the same between them all. Do i use inner join, left join, right join, full join? (what even is the difference) and how would i arrange it in a query? thanks for any help Quote Link to comment Share on other sites More sharing options...
Guest Posted January 6, 2014 Share Posted January 6, 2014 You missed out natural join ^_^. I would use inner join, if one of the tables doesn't contain data it won't return anything, left and right join simply adds the data to left or right side of the main table. I believe that's how it works, Quote Link to comment Share on other sites More sharing options...
Coly010 Posted January 7, 2014 Author Share Posted January 7, 2014 Okay, so when doing it, do I: SELECT u.*, t.*, a.* FROM user u INNER JOIN table t ON u.userid = t.userid INNER JOIN another_table ON u.userid = a.userid WHERE u.userid = $userid Should that work? Quote Link to comment Share on other sites More sharing options...
Seker Posted January 7, 2014 Share Posted January 7, 2014 Found this site, which diagrams it for a visual comparison. Worth a look. http://www.khankennels.com/blog/index.php/archives/2007/04/20/getting-joins/ Quote Link to comment Share on other sites More sharing options...
Coly010 Posted January 7, 2014 Author Share Posted January 7, 2014 (edited) Still can't really get my head wrapped around the "matches" part of it. does it only take the row from the other table which has the same column name and value as all the column names in the first table? Or does it give you the full row if as long as one column matches a certain column in the other table? inner join didnt work, left join did work :S Edited January 7, 2014 by !Angel Quote Link to comment Share on other sites More sharing options...
Guest Posted January 7, 2014 Share Posted January 7, 2014 INNER won't work if there is no data in any of the other tables that relate. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.