Return customers who have at least one order without duplicating customer rows.
Section: Semi-joins
Use EXISTS for semi-join behavior
sql
sql
SELECT c.customer_id, c.name
FROM customers c
WHERE EXISTS (
SELECT 1
FROM orders o
WHERE o.customer_id = c.customer_id
);Explanation
`EXISTS` is often clearer and more efficient than joining and deduplicating.
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 Semi-joins
Use IN for simple membership checks
Another semi-join style when selecting from a single column set.
Be careful with NOT IN and NULLs
A single `NULL` in the subquery can change results in surprising ways.