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