Missing Values: NULL

You know NULL from the first lesson: it means that a value is missing. The shop doesn't know Ava Green's city, and Robot Rebellion has no release date yet. To find such rows, it seems natural to write = NULL. But this query finds nothing:

SELECT name, city
FROM customers
WHERE city = NULL;
namecity

That's not a mistake in the data. NULL means “unknown”, and comparing anything with an unknown value gives an unknown result. Is London equal to some unknown city? Nobody knows. Such a comparison is neither true nor false; its result is NULL again. And WHERE keeps only the rows for which the condition is true. Not even NULL = NULL is true: are two unknown cities the same? Unknown again. You can try it yourself: a SELECT without FROM reads no table, it just works out the values you write and shows them as one row:

SELECT 5 = NULL, NULL = NULL;
5 = NULLNULL = NULL
NULLNULL

That's why SQL has a special operator for missing values, IS NULL. The games that aren't out yet:

SELECT title, released
FROM games
WHERE released IS NULL
ORDER BY title;
titlereleased
Mystery ManorNULL
Robot RebellionNULL

Its opposite is IS NOT NULL, the rows that do have a value: WHERE released IS NOT NULL finds the 18 games that are out.

The same goes for every other comparison, <> included. Which customers aren't from London?

SELECT name, city
FROM customers
WHERE city <> 'London'
ORDER BY name;
namecity
Isla YoungLeeds
Jack HarrisManchester
Liam TurnerManchester
……

Ava Green and Henry Scott aren't in the result. Is an unknown city different from London? Unknown again. If you want them too, you have to ask for them: city <> 'London' OR city IS NULL.

Typical mistake: = NULL instead of IS NULL. It isn't an error, so SQLite won't warn you; the query just finds nothing. Whenever you look for missing values, write IS NULL.

Instructions

The query in the editor should show the name and the email of the customers who have no city, but it finds nothing. Fix it:

nameemail
Ava Greenava.green@mail.com
Henry Scotthenry@scott.dev

Below it, show the game ID, the stars and the comment of the five-star reviews that have a comment, sorted by game ID:

game_idstarscomment
15Best RPG I have played in years!
35So relaxing.
65Perfect for the bus.
75Amazing space battles.
145Fast and fun.
155Worth every penny.

The shop is writing a newsletter about new games: those released in 2025 or later, and those that aren't out yet. Show their title and release date, sorted by release date and then by title:

titlereleased
Mystery ManorNULL
Robot RebellionNULL
Star Pilots2025-01-23
Turbo Karts2025-06-05
Goal Rush2025-09-26
Knight's Oath2025-11-14

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

11/11