Sql Self Join — Free Sql Tutorial
Learn Sql Self Join in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Sql Self Join in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Sql Self Join in Sql
A self-join joins a table to a copy of itself, useful for finding relationships within the same table: employee-manager hierarchy, product comparisons, duplicate detection.
Use table aliases (a, b) to distinguish the two copies: FROM employees e1 JOIN employees e2 ON e1.manager_id = e2.emp_id.
Common uses: "find all employees and their managers", "find products in the same category with price differences", "find pairs of employees in the same department".
Sql Self Join — Syntax
-- Employee and manager (both from employees table) SELECT e.name AS employee, m.name AS manager FROM employees e LEFT JOIN employees m ON e.manager_id = m.emp_id; -- Find pairs of friends in the same city SELECT f1.name, f2.name, f1.city FROM friends f1 JOIN friends f2 ON f1.city = f2.city AND f1.
Learn Sql Self Join step by step with Syllab's free interactive Sql tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Sql course →