The PostgreSQL ALL operator is used for comparing a value with a list of values returned by a subquery.
Syntax: comparison_operator ALL (subquery)
The below rules need to be followed while using the ALL operator:
- The ALL operator always needs to be preceded by a comparison operator(=, !=, <, >, >=, <=).
- It must always be followed by a subquery surrounded by parentheses.
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.
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(>).
SELECT film_id, title, length FROM film WHERE length > ALL ( SELECT ROUND(AVG (length), 2) FROM film GROUP BY rating ) ORDER BY length;
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(<).
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;
- PostgreSQL - BETWEEN operator
- PostgreSQL - NOT BETWEEN operator
- PostgreSQL - LIKE operator
- PostgreSQL - ANY Operator
- PostgreSQL - IN operator
- PostgreSQL - NOT IN operator
- PostgreSQL - NOT LIKE operator
- PostgreSQL - SOME Operator
- PostgreSQL - EXCEPT Operator
- PostgreSQL - UNION operator
- PostgreSQL - EXISTS Operator
- PostgreSQL - INTERSECT Operator
- PostgreSQL - ILIKE operator
- PostgreSQL - IS NULL operator
- PostgreSQL - CTE
- PostgreSQL - UPDATE
- PostgreSQL - INSERT
- PostgreSQL - SELECT INTO
- PostgreSQL - DELETE
- PostgreSQL - Schema
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.