Bird
0
0

Find the error in this query:

medium📝 Debug Q6 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Find the error in this query:
SELECT user_id, ARRAY_AGG(product ORDER BY) FROM purchases GROUP BY user_id;
AARRAY_AGG cannot be used with ORDER BY
BGROUP BY clause is missing user_id
CORDER BY clause inside ARRAY_AGG is incomplete and missing a column
DSELECT statement is missing FROM clause
Step-by-Step Solution
Solution:
  1. Step 1: Review ORDER BY syntax inside ARRAY_AGG

    ORDER BY inside ARRAY_AGG requires a column to order by, e.g., ORDER BY product.

  2. Step 2: Analyze the query

    The query has ORDER BY with no column specified, which is a syntax error.

  3. Step 3: Check other clauses

    GROUP BY user_id is correct, and FROM clause is present.

  4. Final Answer:

    ORDER BY clause inside ARRAY_AGG is incomplete and missing a column -> Option C
  5. Quick Check:

    ORDER BY inside ARRAY_AGG must specify a column [OK]
Quick Trick: ORDER BY inside ARRAY_AGG needs a column name [OK]
Common Mistakes:
  • Leaving ORDER BY empty inside ARRAY_AGG
  • Confusing GROUP BY requirements
  • Assuming ORDER BY is not allowed inside ARRAY_AGG

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes