skip to today's puzzle

EXISTS asks 'is there at least one?'

EXISTS runs a small query for each row and answers yes or no: it checks whether at least one matching row is there, not what that row contains. NOT EXISTS flips it to 'nothing at all', which is a clear way to ask for customers who placed no order.

A tiny example

In plain English: Show me the customers who have no matching row in the orders table.

SELECT c.name
FROM customers c
WHERE NOT EXISTS (
  SELECT 1
  FROM orders o
  WHERE o.customer_id = c.id
);

Query result

name
Sana

Sana is the only customer with no matching row in the orders table, so she’s the only row.

Related SQL lessons

Ready for a break?

A fresh, bite-sized SQL puzzle waits every morning. Tap tiles, see real results. No terminal, no setup, no timers.

Try today's free SQL puzzle