Recall & Review
beginner
What is a Self JOIN in SQL?
A Self JOIN is when a table is joined with itself. It helps compare rows within the same table by treating it as if there were two tables.
Click to reveal answer
beginner
Why would you use a Self JOIN?
You use a Self JOIN to find relationships between rows in the same table, like finding an employee's manager in an employee table.
Click to reveal answer
beginner
In a Self JOIN, why do we use table aliases?
Table aliases give the same table different names so SQL can tell which copy of the table you mean when comparing rows.
Click to reveal answer
intermediate
Write a simple Self JOIN query to find employees and their managers from an employee table with columns (id, name, manager_id).
SELECT e.name AS Employee, m.name AS Manager FROM employee e LEFT JOIN employee m ON e.manager_id = m.id;
Click to reveal answer
beginner
What happens if you forget to use aliases in a Self JOIN?
SQL will get confused because it can't tell which instance of the table you mean, causing errors or unexpected results.
Click to reveal answer
What does a Self JOIN do?
✗ Incorrect
A Self JOIN joins a table with itself to compare rows within the same table.
Why are aliases important in a Self JOIN?
✗ Incorrect
Aliases let you treat the same table as two different tables in the query.
In a Self JOIN, if you want to find an employee's manager, which column would you join on?
✗ Incorrect
You join employee.manager_id to manager.id to link employees to their managers.
What type of JOIN is commonly used in Self JOIN to include employees without managers?
✗ Incorrect
LEFT JOIN includes all employees even if they don't have a manager.
Which of these is a valid alias usage in a Self JOIN?
✗ Incorrect
Using different aliases like e and m helps SQL distinguish the two instances of the same table.
Explain what a Self JOIN is and give a simple example scenario where it is useful.
Think about how one table can relate to itself.
You got /3 concepts.
Describe the role of table aliases in a Self JOIN and what problems they solve.
Why can't you just write the table name twice without aliases?
You got /3 concepts.