MyBB Community Forums

Full Version: JOIN LEFT, RIGHT, INNER help?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Guys could you please explain how to use SQL query:
JOIN LEFT
JOIN RIGHT
JOIN INNER

I know basics but what I need is a simple visual explanation. Please use a bit of code to explain how to use each of them?
Here a nice picture:
[Image: Visual_SQL_JOINS_V2.png]
Thanks buddy. They all look similar to me?

Can I do this:

 LEFT JOIN ".TABLE_PREFIX."posts p ON (post.id=p.pid)
 RIGHT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid)
They're not similar, every has another function. These 'circles' are Venn diagrams and show you which parts of sets will be considered from Table A and Table B.

And since I don't know what you're trying to achieve there is no way I can tell whether your part of query is correct (once again, post whole queries and/or codes)...
Why not simply use LEFT JOIN for all tables? I don't get it what is the point of joining from left or right or inner?
Sorry for being so du*b really struggling with this Smile


SELECT u.uid, u.username, post.id
FROM ".TABLE_PREFIX."pids
LEFT JOIN ".TABLE_PREFIX."posts p ON (post.id=p.pid)
LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid)
Because they do totally different things. The diagrams above show this, if you always used Left joins, you'd get totally different results. Queries are typically Inner or Left joins, but depending on what you need to select or the conditions the join needs to meet, you might need a different type of join.
Matt please give some example MYBB query please?
What, examples from the code? You'd probably be able to find them by searching the codebase just as quickly as I could Smile I don't know if we even need to use any though.
Guys thanks very much I am now watching tutorials on YouTube Smile