Bird
0
0

Find the issue in this query:

medium📝 Debug Q7 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Find the issue in this query:
SELECT ARRAY_AGG(DISTINCT product) FROM orders GROUP BY customer_id;
AMissing customer_id in SELECT list when using GROUP BY
BARRAY_AGG does not support DISTINCT keyword
CCannot use DISTINCT inside ARRAY_AGG with GROUP BY
DGROUP BY should be removed for ARRAY_AGG
Step-by-Step Solution
Solution:
  1. Step 1: Understand GROUP BY requirements

    When grouping by customer_id, it must appear in SELECT list to identify groups.
  2. Step 2: Check ARRAY_AGG with DISTINCT

    ARRAY_AGG supports DISTINCT; no error there.
  3. Final Answer:

    Missing customer_id in SELECT list when using GROUP BY -> Option A
  4. Quick Check:

    GROUP BY columns must be in SELECT list [OK]
Quick Trick: Include GROUP BY columns in SELECT list with ARRAY_AGG [OK]
Common Mistakes:
  • Omitting GROUP BY column in SELECT
  • Thinking DISTINCT is unsupported
  • Removing GROUP BY incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes