Bird
0
0

What will this query return?

medium📝 query result Q5 of 15
PostgreSQL - Subqueries in PostgreSQL
What will this query return?
SELECT product_name FROM products WHERE price < (SELECT AVG(price) FROM products);
AProducts priced below the average price
BProducts priced above the average price
CAll products regardless of price
DError because AVG cannot be used in subquery
Step-by-Step Solution
Solution:
  1. Step 1: Calculate average price using subquery

    The subquery returns the average price of all products.
  2. Step 2: Filter products with price less than average

    Main query selects products cheaper than this average.
  3. Final Answer:

    Products priced below the average price -> Option A
  4. Quick Check:

    Subquery calculates average, main query filters below it [OK]
Quick Trick: Use subqueries to compare values against aggregates like AVG [OK]
Common Mistakes:
  • Thinking AVG cannot be used in subqueries
  • Confusing less than with greater than
  • Expecting all products to be returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes