SQL Practice Logo

SQLPractice Online

Self Joins: Concept

Module: Joins & Relationships

Self join is joining a table to itself using different aliases. Treats the same table as two separate tables to compare or relate rows within it.

Self joins use table aliases to reference the same table twice. Common for hierarchical data (employees with managers), comparing rows, or finding relationships within same entity.

Self joins are essential for hierarchical data and relationships within the same entity. Every organizational chart, social network, and recommendation system uses self joins.

Employee-manager hierarchies use self joins. Social networks use self joins for friend relationships. E-commerce uses self joins for product recommendations ("customers who bought X also bought Y").