Greater than

2 snippets in SQL

Also written as greater than all

SQLSQL

Comparison Operators

SQL · Filtering
syntax
WHERE column = | <> | < | > | <= | >= value
example
SELECT product_name, price
FROM products
WHERE price >= 50.00 AND price < 200.00;
output
-- Products priced from 50 up to (not including) 200

Note Use <> for not-equal (ANSI standard). != works in MySQL and PostgreSQL but is not part of the standard.

ANY and ALL

SQL · Filtering
syntax
WHERE column > ANY (subquery)
WHERE column > ALL (subquery)
example
SELECT product_name, price
FROM products
WHERE price > ALL (
  SELECT AVG(price)
  FROM products
  GROUP BY category_id
);
output
-- Products priced above every category's average

Note ANY means the condition must be true for at least one value from the subquery. ALL means it must be true for every value. If the subquery returns an empty set, ALL conditions are true and ANY conditions are false.