Loading
SQL ANY Operator
The ANY operator in SQL allows you to compare a value against any value in a list or subquery. It returns TRUE if at least one of the values satisfies the condition.



Syntax:

SELECT column_name FROM table_name WHERE column_name operator ANY (subquery);

  • operator can be: =, !=, >, <, >=, <=
  • The condition is TRUE if any one of the values in the subquery satisfies the condition



Products Table

product_idproduct_namepricecategory
1Laptop50000Electronics
2Smartphone25000Electronics
3Chair3000Furniture
4Desk6000Furniture
5TV40000Electronics



Example: 

Goal: List all products with a price grater than any product in the Electronics category.

SELECT product_name FROM products WHERE price > ANY (SELECT price FROM products WHERE category = 'Electronics');

Output:

product_name
Laptop
TV

Explanation: This query compares each product's price with every price in the Electronics category.
It returns products whose price is greater than at least one price in that category.



Comparison: ANY vs ALL

OperatorCondition TypeReturns Result
ANYAt least one trueOne or more comparisons are true
ALLMust be all trueAll comparisons in the set are true