Employees Missing a Department
Easysql
The department column should really be NOT NULL, but the constraint was never added, so some rows slipped through with a missing department. Write a query returning id and name for every employee whose department is NULL, ordered by id.
sqlCREATE TABLE employees ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, department TEXT, salary INTEGER );
Sample data:
sqlINSERT INTO employees (id, name, department, salary) VALUES (1, 'Asha', 'Engineering', 85000), (2, 'Rohan', NULL, 62000), (3, 'Neha', 'Sales', -500), (4, 'Vikram', 'Sales', 71000);
Example 1
Input
(none)
Output
id name 2 Rohan
IS NULL is the only correct way to test for a missing value. Reference: SELECT id, name FROM employees WHERE department IS NULL ORDER BY id;