The Wayback Machine - https://web.archive.org/web/20261118122131/https://www.geeksforgeeks.org/postgresql/postgresql-any-operator/

PostgreSQL - ANY Operator

Last Updated : 4 Nov, 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 column_1, column_2, ...
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.

employee table:

Screenshot-2026-10-04-180042

department table:

Screenshot-2026-10-04-180059

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 employee_name
FROM employee
WHERE salary > ANY (
SELECT min_salary
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 employee_name, salary
FROM employee
WHERE salary > ANY (ARRAY[40000, 60000])
AND employee_id > 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 employee_id is greater than 101.

Comment

Explore