Return users who have at least one paid order.
Section: subqueries and ctes
Filter with a subquery
sql
sql
SELECT id, email
FROM users
WHERE id IN (
SELECT user_id FROM orders WHERE status = 'paid'
);Explanation
A simple subquery pattern for membership-based filtering.
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 subqueries and ctes
Use a CTE to isolate recent orders
Create a readable query pipeline with `WITH`.
Left join to keep unmatched parent rows
Return all rows from the left table and matching rows from the right table.