SQL · Pattern 8 — Subqueries
ANY (SOME)
The ANY (or SOME) operator compares a value with each value returned by the subquery.
Source data — Pattern 8: Subqueries
All queries run against the shared employees and departments tables (see schema.sql). This pattern introduces scalar, correlated, and multiple-row subqueries. Topics 47 and 48 demonstrate the EXISTS and NOT EXISTS operators, while Topics 49 and 50 introduce the ANY (SOME) and ALL comparison operators.


What it does
The ANY (or SOME) operator compares a value with each value returned by the subquery. The condition is true if it matches at least one value.
Problem
Find employees earning more than any HR employee.
SELECT first_name, salary
FROM employees
WHERE salary > ANY (
SELECT salary
FROM employees
WHERE department_id = 200
);
Result
