Return rows when a related row exists.
Section: EXISTS and Set Operations
Filter with EXISTS
sql
sql
SELECT c.customer_id
FROM customers c
WHERE EXISTS (
SELECT 1
FROM orders o
WHERE o.customer_id = c.customer_id
);Explanation
EXISTS is often efficient for existence checks.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing EXISTS and Set Operations
Combine result sets with UNION
Merge distinct rows from two compatible queries.
Subtract rows with EXCEPT
Return rows from the first query not present in the second.