Interview Question

What is SELF JOIN?

A self join relates rows within the same table by using aliases.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

A self join joins a table to another reference of the same table. • Aliases distinguish the two roles. • It is useful for parent-child or peer relationships stored in one table. • The join still follows the rules of its chosen inner or outer join type.

💡 SQL Example

SELECT e.name, m.name AS manager FROM employees e LEFT JOIN employees m ON m.employee_id = e.manager_id;

Result

Employee and manager names

⚡ Quick Revision

A self join relates rows within the same table by using aliases.