Skip to content
We areTOP 1%

Customers Who Never Order

EasyLeetCodeSQL: Subqueries & CTEs
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Hint and exampleShow

Return the rows of one table that have no match in another with NOT EXISTS (or LEFT JOIN ... IS NULL), and avoid NOT IN when the subquery can contain NULL.

Example: authors(id, name) and books(id, author_id)

authors        books
id | name      id | author_id
1  | Asha      10 | 1
2  | Ravi      11 | 1
3  | Meera
SELECT a.name
FROM authors a
WHERE NOT EXISTS (SELECT 1 FROM books b WHERE b.author_id = a.id);
-- returns Ravi, Meera

More in SQL: Subqueries & CTEs

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account