SQL and JOIN clause (really simple)

Hello everyone,

This is the first time I post something, hopefully I haven’t done it wrong.

My question has to do more with simple logic. I am learning about JOIN clauses. But for me it seems counter-intuitive the way you do JOIN (unless I am getting it wrong all together!)

So to use a real world example, if I am baking a cake and I want to ‘join’ sugar into the mix I don’t pour the mix into the sugar but instead the sugar into the mix.

See this exercise and correct answer:

  • Join plans and premium_users and select:
    ** user_id from premium_users
    ** description from plans

SELECT premium_users.user_id,
plans.description
FROM premium_users
JOIN plans
ON plans.id = premium_users.membership_plan_id;


The exercise mentions to join plans and premium_users. So in my head that means ‘pour premium into plans’. But the answer seems to point at doing it the other way around? I can’t get my head around it!

https://www.codecademy.com/paths/data-science/tracks/sql-intermediate/modules/dspath-sql-multiple-tables/lessons/sql-multiple-tables-code-challenge/exercises/inner-join

@frankjimenez93270473,

Welcome to the Codecademy Forums!

In this particular case, it actually doesn’t matter if you are “pouring” premium into plans or plans into premium because you are using an inner join. With inner joins, your query will only return rows where both tables match the ON condition. So here, the only difference between…

SELECT premium_users.user_id, plans.description
FROM premium_users
JOIN plans 
ON plans.id = premium_users.membership_plan_id;

…and…

SELECT premium_users.user_id, plans.description
FROM plans
JOIN premium_users
ON premium_users.membership_plan_id = plans.id;

…is the order they are returned in.

However, if you are doing a LEFT JOIN, the order matters very much.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.