Example 1
Find employees who have no manager
Alice has no manager (NULL), so she is the top-level employee. WHERE manager_id = NULL would return no rows because comparisons with NULL are never true — IS NULL is the correct operator. Use IS NOT NULL to find the opposite: all employees who do have a manager.
CREATE TABLE employees (id INT, name VARCHAR(50), manager_id INT);
INSERT INTO
employees (id, name, manager_id)
VALUES
(1, 'Alice', NULL),
(2, 'Bob', 1),
(3, 'Carol', 1);SELECT
name
FROM
employees
WHERE
manager_id IS NULL
ORDER BY
name;| name |
|---|
| Alice |
Output is identical across all engines.