SQL IS NULL Practice: Finding Unreturned Rentals
Missing data is a signal: an empty returned_date means the movie is still on loan.
In rentals, a returned movie has a returned_date. A movie still on loan has none, so the value is NULL. Finding those rows is how a shop knows what is still out on the shelves.
NULL means "unknown", so it never equals anything, not even another NULL. That is why returned_date = NULL silently matches zero rows.
Use IS NULL, not = NULL
Test for missing values with IS NULL (and its partner IS NOT NULL). This is one of the most common beginner mistakes, and it fails quietly: no error, just an empty result. Joining to customers and movies turns the raw ids into a report someone can act on.
select columns
from table_name
where nullable_column is nullSchema · Movie RentalsTable · rentals6 columns · 26 rows
One row per rental. Movies still out have a null returned_date.
List every rental that has not been returned. Return the customer's first and last name, the movie title, and the rental date, oldest first.
- Columns: first_name, last_name, title, rental_date.
- Rows: 6 rentals still checked out.
- The oldest unreturned rental is Sofia Ramirez with The Last Orchard on 2023-06-05.
Related
Find missing values with IS NULL.
Keep NULLs from silently changing filter results.
IS NULL, COALESCE, NULLIF, and null-safe logic.
IS NULL, COALESCE, NULLIF, and null-safe equality.