๐๐ป๐๐ฒ๐ฟ๐๐ถ๐ฒ๐๐ฒ๐ฟ: List all employees and their managers. If an employee doesnโt have a manager, still include them.
๐ ๐ฒ: Using a self-join with LEFT JOIN:
SELECT e.name AS employee_name, m.name AS manager_name
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.id;
โ Why it works:
โ LEFT JOIN ensures employees without managers are still included.
โ Self-join allows referencing the same table for managers.
โ Simple and clean solution for interviews.
๐ Bonus Tip:
Always consider null values in joins; LEFT JOIN helps preserve the main table rows even if the related data is missing.
๐ฌ Tap โค๏ธ if this helped you!