#820

Spot a sneaky NULL bug and route around it

The «find customers who have no orders» query phrased with NOT IN carries a nasty bug: if the subquery contains even a single NULL row, the whole NOT IN silently returns zero rows — no error, no warning. A classic three-valued-logic trap in SQL. The safe equivalent is NOT EXISTS: it returns a row when the inner query found nothing, and is immune to NULL. Rewrite the «customers without orders» check using NOT EXISTS so the query works correctly even with NULL in the data. Show the id and email of such customers, sort by id.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.

idemail
3новый@email

Your query result will appear here