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 - NOT IN operator
- PostgreSQL - IN operator
- PostgreSQL - NOT LIKE operator
- PostgreSQL - ILIKE operator
- PostgreSQL - IS NULL operator
- PostgreSQL - LIKE operator
- PostgreSQL - NOT BETWEEN operator
- PostgreSQL - BETWEEN operator
- PostgreSQL - UNION operator
- PostgreSQL - INTERSECT Operator
- PostgreSQL - EXCEPT Operator
- PostgreSQL - ANY Operator
- PostgreSQL - SOME Operator
- PostgreSQL - EXISTS Operator
- PostgreSQL - Create Database
- PostgreSQL - COALESCE
- PostgreSQL - CASE Statement
- PostgreSQL - IF Statement
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.