Skip to main content
← Back to Code Arena
Hard Engineer SpeedRun null three-valued-logic subqueries

SQL: NOT IN With NULL Returns Nothing

+220 XP · 6 min · attempt 1

Problem

Tables:

    customers(id):  1, 2, 3, 4
    blocked(id):    2, NULL

Query:

    SELECT id FROM customers
    WHERE id NOT IN (SELECT id FROM blocked);

How many rows does this return? Enter a single integer.

Starter

-- NOT IN against a list containing NULL behaves... unexpectedly.
-- id <> NULL is UNKNOWN, and NOT IN expands to a chain of <> ANDs.

Your answer

Playing as a guest — you'll be asked for a display name on submit. Log in to keep your XP across devices.