PostgreSQL - ANY Operator

Last Updated : 28 Jul, 2026

The ANY operator in PostgreSQL is used to compare a value with a set of values returned by a subquery or an array. The condition evaluates to TRUE if at least one value in the set satisfies the comparison.

  • Supports comparison operators such as =, >, <, >=, <= and <>.
  • Commonly used with subqueries.

Syntax

SELECT column1, column2, ...
FROM table_name
WHERE expression comparison_operator ANY (
subquery
);

Where:

  • expression: The value to compare.
  • comparison_operator: Operators such as =, >, <, >=, <= or <>.
  • ANY: Returns TRUE if at least one comparison is true.
  • subquery: Returns a single-column result set.

Examples

Firstly, create the Department and Employee tables and insert some records.

Screenshot-2026-07-13-095647
Employee Table
Screenshot-2026-07-13-095723
Department Table


Example 1: Basic Use with an Array

SELECT *
FROM Employee
WHERE Salary = ANY (ARRAY[45000, 65000]);

Output:

Screenshot-2026-07-13-095832

Example 2: Use with a Subquery

SELECT EmployeeName
FROM Employee
WHERE Salary > ANY (
SELECT MinSalary
FROM Department
);

Output:

Screenshot-2026-07-13-095909

This query returns employees whose salary is greater than at least one department's minimum salary.

Example 3: Use with NOT ANY

SELECT *
FROM Employee
WHERE NOT (Salary = ANY (ARRAY[45000, 65000]));

Output:

Screenshot-2026-07-13-095951

This query retrieves employees whose salary is not equal to 45000 or 65000.

Example 4: Combining Conditions

SELECT EmployeeName, Salary
FROM Employee
WHERE Salary > ANY (ARRAY[40000, 60000])
AND EmployeeID > 101;

Output:

Screenshot-2026-07-13-100023

This query returns employees whose salary is greater than at least one value in the array and whose EmployeeID is greater than 101.

Comment

Explore