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.

Frequently asked questions

How does SQL handle greater than?
SQL covers this with 2 copy-ready snippets on this page. The "Comparison Operators" snippet in SQL uses `WHERE column = | <> | < | > | <= | >= value`.
Which statement does the SQL example use?
The "Comparison Operators" snippet uses `WHERE column = | <> | < | > | <= | >= value`, from the Filtering section of the SQL cheat sheet.
What other SQL snippets are shown for "greater than"?
Besides "Comparison Operators", this page also shows "ANY and ALL".
Is there anything to watch out for?
Yes. For "Comparison Operators": Use <> for not-equal (ANSI standard). != works in MySQL and PostgreSQL but is not part of the standard.