Company: Meta | Difficulty: medium
Meta's people analytics team wants to display each employee alongside their direct manager.
Return each employee's name and their manager's name. Employees without a manager must still appear, with NULL as the manager value.
Sort the results by employee name in descending alphabetical order.
Alice Smith, Charlie Brown, and Evan Wright have no manager, so their manager values are NULL. Bob Jones reports to Alice Smith, and Diana Prince reports to Charlie Brown. The result is sorted by employee name from Z to A.
DROP TABLE IF EXISTS employees; CREATE TABLE employees ( id INT, name VARCHAR(100), manager_id INT ); INSERT INTO employees VALUES (1, 'Alice Smith', NULL), (2, 'Bob Jones', 1), (3, 'Charlie Brown', NULL), (4, 'Diana Prince', 3), (5, 'Evan Wright', NULL);
← All SQL Challenges · Meta Questions · Learn SQL Free