A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/postgresql/postgresql-all-operator/ below:

PostgreSQL - ALL Operator - GeeksforGeeks

PostgreSQL - ALL Operator

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.

Syntax
comparison_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 Examples

Let 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 Lengths

Here 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:

Example 2: Querying Films with Lower Rental Rates Than Average

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:

Important Points About the PostgreSQL ALL Operator


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