📖
Theory
Understand the concept step by step
A SELF JOIN joins a table to itself.
It is useful when rows in the same table have relationships with other rows in that table, such as employees and their managers.
💻
Example
See how the concept works in SQL
SQL
SELECT
e.name AS employee,
m.name AS manager
FROM employees e
JOIN employees m
ON e.manager_id = m.id;📤
Output
Understand what the query produces
Employees are matched with their managers from the same table.
📝
Practice
Test your understanding
Create an employee-manager relationship and query it using a self join.
❓
MCQs
Check your SQL knowledge
What is the main concept covered in SELF JOIN?
A.Joining a table with itself
B.Joining three databases
C.Joining only NULL rows
D.Joining unrelated tables
💼
Interview Questions
Prepare for SQL interviews
1
Interview Question
What is a SELF JOIN?
2
Interview Question
Why would a table be joined to itself?
3
Interview Question
Why are table aliases useful in SELF JOIN?