0
0
PostgreSQLquery~20 mins

ALL, ANY, SOME with subqueries in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ALL, ANY, SOME Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of ALL with subquery
Given a table products with columns id, price, and category, what is the output of this query?
SELECT id FROM products WHERE price > ALL (SELECT price FROM products WHERE category = 'Books');
PostgreSQL
SELECT id FROM products WHERE price > ALL (SELECT price FROM products WHERE category = 'Books');
AReturns IDs of products priced higher than at least one product in the 'Books' category
BReturns IDs of products priced lower than every product in the 'Books' category
CReturns IDs of products priced higher than every product in the 'Books' category
DReturns IDs of products priced equal to the highest price in the 'Books' category
Attempts:
2 left
💡 Hint
ALL means the condition must be true for every value returned by the subquery.
query_result
intermediate
2:00remaining
Output of ANY with subquery
Consider a table employees with columns id, salary, and department. What does this query return?
SELECT id FROM employees WHERE salary < ANY (SELECT salary FROM employees WHERE department = 'Sales');
PostgreSQL
SELECT id FROM employees WHERE salary < ANY (SELECT salary FROM employees WHERE department = 'Sales');
AEmployees with salary less than all employees in Sales
BEmployees with salary less than at least one employee in Sales
CEmployees with salary equal to the lowest salary in Sales
DEmployees with salary greater than all employees in Sales
Attempts:
2 left
💡 Hint
ANY means the condition must be true for at least one value from the subquery.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this ALL query
Which option contains a syntax error when using ALL with a subquery in PostgreSQL?
PostgreSQL
SELECT id FROM orders WHERE amount > ALL SELECT amount FROM orders WHERE status = 'completed';
AMissing parentheses around the subquery after ALL
BUsing ALL instead of ANY causes syntax error
CSubquery must use DISTINCT keyword with ALL
DALL cannot be used with numeric columns
Attempts:
2 left
💡 Hint
Check if the subquery is properly enclosed.
optimization
advanced
2:00remaining
Optimizing ANY with subquery for performance
You have a large sales table with columns id, region, and amount. Which query is more efficient to find sales with amount less than any sale in region 'East'?
ASELECT id FROM sales WHERE amount < (SELECT MAX(amount) FROM sales WHERE region = 'East');
BSELECT id FROM sales WHERE EXISTS (SELECT 1 FROM sales s2 WHERE s2.region = 'East' AND amount < s2.amount);
CSELECT id FROM sales WHERE amount IN (SELECT amount FROM sales WHERE region = 'East');
DSELECT id FROM sales WHERE amount < ANY (SELECT amount FROM sales WHERE region = 'East');
Attempts:
2 left
💡 Hint
Rewrite ANY with an aggregate function to reduce subquery size.
🧠 Conceptual
expert
2:00remaining
Understanding SOME synonym behavior
In PostgreSQL, which statement about the SOME keyword is correct?
ASOME requires the subquery to return only one row
BSOME returns true only if all values satisfy the condition
CSOME cannot be used with NOT operator
DSOME is a synonym for ANY and behaves identically in queries
Attempts:
2 left
💡 Hint
Check PostgreSQL documentation for SOME keyword meaning.