Bird
0
0

Why does the query SELECT * FROM items WHERE price > ALL (SELECT price FROM items WHERE price return all rows if all prices are 100 or more?

hard📝 Conceptual Q10 of 15
PostgreSQL - Subqueries in PostgreSQL
Why does the query SELECT * FROM items WHERE price > ALL (SELECT price FROM items WHERE price < 100); return all rows if all prices are 100 or more?
ABecause ALL with an empty subquery always returns true
BBecause ALL with an empty subquery always returns false
CBecause price cannot be compared with ALL in this case
DBecause the subquery returns multiple columns
Step-by-Step Solution
Solution:
  1. Step 1: Understand subquery result

    The subquery selects prices less than 100. If none exist, subquery returns empty set.
  2. Step 2: Behavior of ALL with empty set

    In SQL, condition with ALL and empty set returns true (vacuous truth).
  3. Step 3: Why query returns all rows

    Since price > ALL (empty) is true for all rows, query returns all rows.
  4. Final Answer:

    Because ALL with an empty subquery always returns true -> Option A
  5. Quick Check:

    ALL with empty set = true (vacuous truth) [OK]
Quick Trick: ALL with empty subquery always returns true [OK]
Common Mistakes:
  • Thinking ALL with empty subquery returns false
  • Assuming subquery returns multiple columns
  • Confusing behavior of ANY and ALL with empty sets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes