Jump to content
MakeWebGames

Recommended Posts

Posted

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

Posted

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,

Posted

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?

Posted (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 by !Angel
Posted

INNER won't work if there is no data in any of the other tables that relate.

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.   Paste as plain text instead

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