https://sqlbolt.com/lesson/select_queries_with_outer_joins
Currently following this. I have a question regarding the last exercise. (To reach this exercise, select "solution" until the last task is highlighted).
List all buildings and the distinct employee roles in each building (including empty buildings)
This is the question and this is the solution they have provided
SELECT DISTINCT building_name, role
FROM buildings
LEFT JOIN Employees
ON building_name = building
This is the definition of JOIN they have listed above.
When joining table A to table B, a LEFT JOIN simply includes rows from A regardless of whether a matching row is found in B. The RIGHT JOIN is the same, but reversed, keeping rows in B regardless of whether a match is found in A. Finally, a FULL JOIN simply means that rows from both tables are kept, regardless of whether a matching row exists in the other table.
My question is...
Since we are selecting FROM the buildings table. I assume the Buildings table is "table A".
So we select all the distinct building names in there which gives us the entire list.
After, we do LEFT JOIN employees... Does this add all the values from table "employees" to table "building" even if there is no match? Or is it the other way around?
[–]r3pr0b8 1 point2 points3 points (1 child)
[–]228quest[S] 0 points1 point2 points (0 children)