Loading
SQL ALL Operator
The ALL operator in SQL is used to compare a single value against a set of values. It returns TRUE only if the condition is satisfied for all values in the list or subquery.



Syntax:

SELECT column1, column2, ... FROM table_name WHERE column_name operator ALL (value1, value2, ...);

  • operator Can be =, !=, >, <, >=, <=
  • The comparison will return TRUE only if the condition holds true for every value in the list



Employee Table

IDEmpNameSalary
1Diya15000
2Preeti30000
3Prabhu40000
4Arya20000



Example: Using All Operator

Goal: List employees whose salary is greater than 15000 and 20000.

SELECT * FROM Emp WHERE Salary > ALL (15000, 20000);

Output:

IDEmpNameSalary
2Preeti30000
3Prabhu40000

Explanation: This condition means: "Show employees whose salary is greater than both 15000 and 20000". So only those earning more than 20000 are included.



Key Point

  • Compare a value with a list or subquery
  • Commonly used with > ALL, < ALL, = ALL
  • Ensures strict filtering when all values must be met