Self Join for Hierarchical Data
📖 Scenario: You work in a company database where employees have managers. Each employee record has an ID and a manager ID that points to another employee. You want to find out who manages whom by linking employees to their managers.
🎯 Goal: Build a SQL query using a self join to list each employee with their manager's name.
📋 What You'll Learn
Create a table called
employees with columns id, name, and manager_id.Insert the exact employee data given.
Write a self join query to link employees to their managers.
Select employee names and their manager names in the output.
💡 Why This Matters
🌍 Real World
Many companies store employee-manager relationships in one table. Self joins help find reporting lines.
💼 Career
Understanding self joins is important for database analysts and developers working with hierarchical data.
Progress0 / 4 steps