๐ ๐ฒ: Hereโs my SQL solution using a LEFT JOIN:
SELECT e.name AS employee_name, d.name AS department_name
FROM employees e
LEFT JOIN departments d ON e.department_id = d.id;
โ Why it works:
โ
LEFT JOIN ensures all employees are shown, even those without departments. โ It joins the
employees and departments tables on department_id. โ Clean, readable, and interview-ready!
๐ Bonus Insight:
Always understand the difference between
INNER JOIN, LEFT JOIN, and RIGHT JOIN. In real-world databases, missing data is common โ use joins wisely to handle it.๐ฌ Tap โค๏ธ if this helped you!