0
0
PostgreSQLquery~10 mins

ANY and ALL with arrays in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select rows where the value is equal to any element in the array.

PostgreSQL
SELECT * FROM products WHERE price = ANY([1]);
Drag options to blanks, or click blank then click option'
AARRAY[10, 20, 30]
B[10, 20, 30]
C(10, 20, 30)
D{10, 20, 30}
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] without ARRAY keyword.
Using curly braces {} which is not valid in SQL queries.
Using parentheses () which is for tuples, not arrays.
2fill in blank
medium

Complete the code to select rows where the value is greater than all elements in the array.

PostgreSQL
SELECT * FROM orders WHERE quantity > ALL([1]);
Drag options to blanks, or click blank then click option'
AARRAY[5, 10, 15]
B[5, 10, 15]
C(5, 10, 15)
D{5, 10, 15}
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces or parentheses instead of ARRAY.
Forgetting the ARRAY keyword.
3fill in blank
hard

Fix the error in the query to correctly check if the column value is less than any element in the array.

PostgreSQL
SELECT * FROM sales WHERE amount < ANY([1]);
Drag options to blanks, or click blank then click option'
A(100, 200, 300)
B[100, 200, 300]
C{100, 200, 300}
DARRAY[100, 200, 300]
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets without ARRAY keyword.
Using curly braces or parentheses instead of ARRAY.
4fill in blank
hard

Fill both blanks to select rows where the score is greater than all elements in the array and less than any element in another array.

PostgreSQL
SELECT * FROM results WHERE score > ALL([1]) AND score < ANY([2]);
Drag options to blanks, or click blank then click option'
AARRAY[50, 60, 70]
BARRAY[80, 90, 100]
C[50, 60, 70]
D[80, 90, 100]
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets without ARRAY keyword.
Mixing array syntax styles.
5fill in blank
hard

Fill all three blanks to select rows where age is less than all elements in one array, greater than any element in another array, and equal to any element in a third array.

PostgreSQL
SELECT * FROM users WHERE age < ALL([1]) AND age > ANY([2]) AND age = ANY([3]);
Drag options to blanks, or click blank then click option'
AARRAY[40, 50, 60]
BARRAY[20, 25, 30]
CARRAY[25, 30, 35]
D[40, 50, 60]
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets without ARRAY keyword.
Using curly braces or parentheses instead of ARRAY.