Return the names of employees whose managerid is NULL. Table definitions (from the source exercise):
SQLLevel: IntermediateAnti-joins and missing data
Return the names of employees whose manager_id is NULL.
Table definitions (from the source exercise):
CREATE TABLE employees(emp_id INTEGER PRIMARY KEY, name TEXT, department_id INTEGER, manager_id INTEGER, salary INTEGER, hire_date TEXT, job_title TEXT, gender TEXT);
Hints
- Distinguish a missing value from zero, an empty string and false.
- Test comparison, aggregation and filtering on a tiny missing-value example.
Answer
Approach: A simple IS NULL filter - no join needed.
SELECT name
FROM employees
WHERE manager_id IS NULL;
The source uses SQLite with a MySQL compatibility layer. Date and string functions are dialect dependent; the query is preserved as published.
Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT