EasySubqueries & EXISTS

EXISTS: find customers who have placed orders

The query

SQL
SELECT name, email, country
FROM customers c
WHERE EXISTS (
  SELECT 1
  FROM orders o
  WHERE o.cust_id = c.cust_id
)
ORDER BY name;
Tested against PostgreSQL 16

Note

EXISTS returns TRUE if subquery finds any row. SELECT 1 is idiomatic (column doesn't matter).

Tables referenced