0
0
PostgreSQLquery~5 mins

ALL, ANY, SOME with subqueries in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the ALL keyword do when used with a subquery in SQL?

ALL compares a value to every value returned by the subquery. The condition is true only if the comparison holds for all values.

Click to reveal answer
beginner
How does ANY differ from ALL in SQL subqueries?

ANY checks if the condition is true for at least one value returned by the subquery. It returns true if any single value satisfies the condition.

Click to reveal answer
beginner
What is the synonym of ANY in SQL when used with subqueries?

SOME is a synonym for ANY. Both work the same way and can be used interchangeably.

Click to reveal answer
intermediate
Write a simple example of using ALL with a subquery to find employees with salary greater than all salaries in department 10.
SELECT employee_name FROM employees WHERE salary > ALL (SELECT salary FROM employees WHERE department_id = 10);
Click to reveal answer
intermediate
Explain why salary > ANY (subquery) might return more rows than salary > ALL (subquery).

salary > ANY (subquery) returns true if salary is greater than at least one value in the subquery, so it matches more rows. salary > ALL (subquery) requires salary to be greater than every value, which is stricter and returns fewer rows.

Click to reveal answer
Which keyword checks if a value is greater than every value returned by a subquery?
AALL
BANY
CSOME
DIN
What does SOME mean in SQL when used with subqueries?
AEquivalent to EXISTS
BEquivalent to ALL
CEquivalent to IN
DEquivalent to ANY
If you want to find rows where a value is less than at least one value in a subquery, which keyword do you use?
AALL
BANY
CNONE
DEXISTS
What will the query SELECT * FROM products WHERE price > ALL (SELECT price FROM products WHERE category = 'Books'); return?
AProducts with price greater than every book price
BProducts with price greater than some book price
CProducts with price equal to any book price
DAll products in the 'Books' category
Which of these is NOT true about ANY and ALL?
A<code>ANY</code> returns true if condition matches at least one value
B<code>ALL</code> returns true if condition matches every value
C<code>ANY</code> and <code>ALL</code> are interchangeable
D<code>SOME</code> is a synonym for <code>ANY</code>
Explain how the ALL keyword works with subqueries in SQL and give a simple example.
Think about how a value compares to every value in a list.
You got /3 concepts.
    Describe the difference between ANY and ALL when used with subqueries and when you might use each.
    Consider how strict the condition is for each keyword.
    You got /3 concepts.