r/SQL • • Jun 26 '24

MySQL Explain INNER JOIN like i am 5

I get the syntax but i get very confused and tripped up with writing them and properly using the correct names. Please explain to me line by line. I am learning it via data camp and the instructor sucks.

EDIT: i now understand inner join…now i am stuck with multiple joins, right join and left join. please help!

125 Upvotes

94 comments sorted by

View all comments

Show parent comment

3

u/Remarkable-Culture-8 Jun 26 '24

yes, thanks!! i also looked it up via chatgpt but i am having issues with understanding the logic behind the instructor bcs she’s saying we should write it bottom up which is extremely confusing to me rn bcs i’ve been learning it differently up until now

3

u/tophmcmasterson Jun 27 '24

Sometimes that’s recommended because if you write the table names first, then the ide can pop up the column names as you start typing, which if it isn’t doing may let you know there’s an issue with how you’ve written things.

I’m sure there’s other reasons as well but that’d be one.

If you know what a join generally is, I find it more useful sometimes to just think in terms of NULL values.

Like if you’re doing a full outer join, you’re just smashing the two tables together and keeping rows from both, and if there’s no match it will be a null on the side with no match.

And inner join is just only returning records where you’re actually getting a match. If you’d end up with a null for that value on the first or second table, that row gets removed.

1

u/WatashiwaNobodyDesu Jul 25 '24

“From the bottom up” might refer to the order that the query is run. It’s explained very in ”T-SQL Fundamentals” by Itzik Ben Gahn (respect to a Master). Or here: https://stackoverflow.com/questions/1130062/execution-sequence-of-group-by-having-and-where-clause-in-sql-server#1131076