Given a table of neighborhoods and a table of users, find every neighborhood that has zero registered users.
The Neighborhoods table lists all known neighborhoods, and the Users table records each user along with the neighborhood_id they belong to. A neighborhood is considered empty if no row in Users references its id.
Return the id and name of each empty neighborhood, ordered by id in ascending order.
Input Table(s)
Neighborhoods (primary key id)
| Column | Type | Meaning |
|---|
| id | INT | Neighborhood id, primary key |
| name | VARCHAR(100) | Neighborhood name, never NULL |
| city_id | INT | City the neighborhood belongs to |
Users (primary key id; neighborhood_id is a foreign key to Neighborhoods(id))
| Column | Type | Meaning |
|---|
| id | INT | User id, primary key |
| name | VARCHAR(100) | User name, never NULL |
| neighborhood_id | INT | Neighborhood the user belongs to, or NULL when the user is not assigned to one |
Output Contract
-
Columns, in this order:
id
,
name
, both taken from
Neighborhoods
.
-
One row per empty neighborhood.
-
Rows ordered by
id
ascending.
id
is unique, so the order is fully determined.
-
No rounding applies.
Example
Neighborhoods
| id | name | city_id |
|---|
| 1 | Downtown | 10 |
| 2 | Uptown | 10 |
| 3 | Midtown | 10 |
| 4 | Riverside | 11 |
Users
| id | name | neighborhood_id |
|---|
| 1 | Alice | 1 |
| 2 | Bob | 1 |
| 3 | Charlie | 3 |
Expected result
Uptown (id 2) and Riverside (id 4) have no registered users, so they are returned in id order. Downtown has two users and Midtown has one, so both are left out.
If every neighborhood has at least one user, the result is empty. For example, a single neighborhood Solo (id 1) with one user Eve whose neighborhood_id is 1 returns no rows.
Constraints and Clarifications
-
Neighborhoods
has 1 to 10,000 rows.
Users
has 0 to 100,000 rows.
-
Neighborhoods.id
and
Users.id
are unique primary keys.
Neighborhoods.name
is never NULL.
-
Users.neighborhood_id
may be NULL, meaning the user is not assigned to any neighborhood. Such a user does not count toward any neighborhood.
-
A neighborhood with several users is not empty and must not appear in the output.
-
When
Users
has no rows, every neighborhood is empty and all of them are returned.
-
city_id
plays no part in the result.