Departments Without Employees
Problem statement
Return every department that currently has no employees assigned to it.
The departments table contains the complete department catalog. The employees.department_id field is nullable for employees who have not yet been assigned. Return each unstaffed department's ID and name in ascending department-ID order.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
departments
| Column | Type | Nullable | Description |
|---|---|---|---|
| department_idPK | Integer | No | — |
| department_name | Text | No | — |
employees
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_idPK | Integer | No | — |
| employee_name | Text | No | — |
| department_id | Integer | Yes | — |
Foreign key: department_id → departments(department_id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| department_id | Integer | No | — |
| department_name | Text | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- Department IDs and employee IDs are unique positive integers.
- Every non-null employee department ID references an existing department.
- Department names are nonempty.
- There may be departments or employees with no matching assignment.