Skip to content
C

Employees Without a Manager

Easysql

Some employees have no manager (manager_id is NULL — they're top-level staff). Write a query returning id and name for employees with no manager, ordered by id ascending.

Reminder: test for NULL with IS NULL, never = NULL (see NULL Semantics) — = NULL never matches anything.

sql
CREATE TABLE employees ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, department TEXT NOT NULL, salary INTEGER NOT NULL, manager_id INTEGER );

Sample data (this is what your query runs against when you press Run):

sql
INSERT INTO employees (id, name, department, salary, manager_id) VALUES (1, 'Asha', 'Engineering', 85000, NULL), (2, 'Rohan', 'Engineering', 72000, 1), (3, 'Neha', 'Sales', 68000, NULL), (4, 'Vikram', 'Sales', 61000, 3), (5, 'Priya', 'Engineering', 79000, 1), (6, 'Karan', 'Marketing', 55000, NULL), (7, 'Divya', 'Marketing', 58000, 6), (8, 'Aman', 'Sales', 64000, 3);

Input (stdin)

Output

Run your code to see output here...