Bird
0
0

Which of the following is the correct way to write a query that selects rows where a column value is less than ALL values returned by a subquery in PostgreSQL?

easy📝 Syntax Q3 of 15
PostgreSQL - Subqueries in PostgreSQL
Which of the following is the correct way to write a query that selects rows where a column value is less than ALL values returned by a subquery in PostgreSQL?
ASELECT * FROM table WHERE column < ANY (SELECT value FROM other_table);
BSELECT * FROM table WHERE column < ALL (SELECT value FROM other_table);
CSELECT * FROM table WHERE column = ALL (SELECT value FROM other_table);
DSELECT * FROM table WHERE column IN ALL (SELECT value FROM other_table);
Step-by-Step Solution
Solution:
  1. Step 1: Understand the syntax for ALL

    The correct syntax uses the comparison operator followed by ALL and a subquery in parentheses.
  2. Step 2: Analyze each option

    SELECT * FROM table WHERE column < ALL (SELECT value FROM other_table); correctly uses column < ALL (subquery). SELECT * FROM table WHERE column < ANY (SELECT value FROM other_table); uses ANY, which is different. SELECT * FROM table WHERE column = ALL (SELECT value FROM other_table); uses = ALL, which is valid but not the requested comparison. SELECT * FROM table WHERE column IN ALL (SELECT value FROM other_table); uses IN ALL, which is invalid syntax.
  3. Final Answer:

    SELECT * FROM table WHERE column < ALL (SELECT value FROM other_table); -> Option B
  4. Quick Check:

    Check for correct operator and parentheses [OK]
Quick Trick: Use operator + ALL + (subquery) syntax [OK]
Common Mistakes:
  • Using ANY instead of ALL
  • Missing parentheses around subquery
  • Using IN with ALL which is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes