EXISTS
SQL · Filteringsyntax
WHERE EXISTS (subquery)example
SELECT u.first_name, u.email
FROM users u
WHERE EXISTS (
SELECT 1 FROM orders o
WHERE o.user_id = u.id
AND o.total_amount > 500
);output
-- Users who have at least one order over 500Note EXISTS stops scanning as soon as it finds one matching row, making it efficient. It generally outperforms IN with large subquery results. The SELECT list inside EXISTS is irrelevant — SELECT 1 is conventional.