Bird
0
0

Identify the error in this query:

medium📝 Debug Q6 of 15
PostgreSQL - Subqueries in PostgreSQL
Identify the error in this query:
SELECT name, (SELECT price FROM products) AS product_price FROM sales;
ANo error, query runs fine
BSubquery returns more than one row causing error
CIncorrect table name in subquery
DMissing alias for subquery result
Step-by-Step Solution
Solution:
  1. Step 1: Check subquery result

    The subquery selects price from products without filtering, so it returns multiple rows.
  2. Step 2: Understand scalar subquery requirement

    Scalar subqueries must return exactly one value; multiple rows cause an error.
  3. Final Answer:

    Subquery returns more than one row causing error -> Option B
  4. Quick Check:

    Scalar subquery must return single value [OK]
Quick Trick: Scalar subqueries must return exactly one row and one column [OK]
Common Mistakes:
  • Not filtering subquery to one row
  • Assuming multiple rows are allowed in scalar subquery
  • Ignoring error messages about subquery returns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes