EXISTS asks 'is there at least one?'
EXISTS runs a small query for each row and answers yes or no — it doesn't care what it found, only whether anything was there. NOT EXISTS flips it to 'nothing at all', which is a clear way to ask for students who joined no club.
A tiny example
In plain English: Show me the students who have no matching row in the clubs table.
SELECT s.name
FROM students s
WHERE NOT EXISTS (
SELECT 1
FROM clubs c
WHERE c.student_id = s.id
);What comes back
| name |
|---|
| Sana |
Sana is the only student with no matching row in the clubs table, so she's the only row.
Related SQL lessons
Ready for a break?
Take on today's cozy puzzle. A fresh, bite-sized query waits every morning — no timers, no pressure.
play today's sip