Last Updated : 12 Jul, 2025
The PostgreSQL ALL operator is a powerful tool for comparing a value with a list of values returned by a subquery. This operator is essential for filtering and querying data based on comparisons with multiple values, making it a valuable addition to any PostgreSQL user's toolkit.
Let us better understand the ALL Operator in PostgreSQL from this article.
Syntaxcomparison_operator ALL (subquery)Key Rules for Using the ALL Operator
The below rules need to be followed while using the ALL operator:
For the sake of this article we will be using the sample DVD rental database, which is explained here and can be downloaded by clicking on this link in our examples.
PostgreSQL ALL Operator ExamplesLet us take a look at some of the examples of ALL Operator in PostgreSQL to better understand the concept.
Example 1: Querying Films Longer Than Average LengthsHere we will query for all films whose lengths are greater than the list of the average lengths by using the ALL and greater than operator(>).
Query:
SELECT film_id, title, length FROM film WHERE length > ALL ( SELECT ROUND(AVG (length), 2) FROM film GROUP BY rating ) ORDER BY length;
Output:
Explanation:
Here we will query for all films whose rental_rate is less than the list of the average rental_rate by using the ALL and less than operator(<).
Query:
SELECT film_id, title, rental_rate FROM film WHERE rental_rate < ALL ( SELECT ROUND(AVG (rental_rate), 2) FROM film GROUP BY rating ) ORDER BY rental_rate;
Output:
Explanation:
- The ALL operator can be used with various comparison operators to filter data based on multiple conditions.
- The ALL operator must always be used with a subquery that provides the list of values for comparison.
- Using the ALL operator with large datasets can impact performance. It is crucial to ensure that subqueries are optimized for efficient execution.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4