SQL 2023 · Joins and combining queries
Check that related rows exist
Return users that have at least one order. EXISTS stops at the first match.
SELECT * FROM users u WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id);
Official SQL 2023 documentation
More joins and combining queries commands
- Join two tables
- Keep rows without a match
- Find rows with no match
- Filter with a subquery
- Stack two result sets
- Name a subquery with a CTE
All joins and combining queries commands · SQL 2023 cheatsheet