Reviewed by Aditya Kumar · Last reviewed 2026-03-24
Manager = employee who is parent_id for at least one other. SQL: SELECT e.id, e.name, CASE WHEN EXISTS (SELECT 1 FROM employees e2 WHERE e2.manager_id = e.id) THEN 'Manager' ELSE 'Non-Manager' END AS role FROM employees e. WHY: EXISTS is efficient—short-circuits; avoids...
Manager = employee who is parent_id for at least one other. SQL: SELECT e.id, e.name, CASE WHEN EXISTS (SELECT 1 FROM employees e2 WHERE e2.manager_id = e.id) THEN 'Manager' ELSE 'Non-Manager' END AS role FROM employees e. WHY: EXISTS is efficient—short-circuits; avoids duplicate scans. Handle NULL manager_id (CEO). SCALABILITY: Index on manager_id; for large orgs, consider materialized view or closure table for hierarchy queries. COST: EXISTS subquery is typically index-only; IN (subquery) can be less optimal in some optimizers.
Red Flag: Forgetting NULL manager_id. Pro-Move: 'We also compute span (direct reports count) and depth for org analytics; use recursive CTE for full hierarchy when needed.'
According to DataEngPrep.tech, this is one of the most frequently asked General/Other interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.