Bird
0
0

Why must all columns in the SELECT list be either in the GROUP BY clause or used with an aggregate function when grouping by a single column?

hard📝 Conceptual Q10 of 15
SQL - GROUP BY and HAVING
Why must all columns in the SELECT list be either in the GROUP BY clause or used with an aggregate function when grouping by a single column?
ATo ensure each selected value corresponds to a single group
BBecause SQL requires all columns to be unique
CTo speed up query execution
DBecause GROUP BY automatically sorts the data
Step-by-Step Solution
Solution:
  1. Step 1: Understand grouping logic

    Grouping combines rows into groups based on column values.
  2. Step 2: Explain column selection rules

    Columns not in GROUP BY must be aggregated to represent one value per group; otherwise, SQL cannot decide which row's value to show.
  3. Final Answer:

    To ensure each selected value corresponds to a single group -> Option A
  4. Quick Check:

    Selected columns must match groups or be aggregated [OK]
Quick Trick: Non-grouped columns need aggregation for single value [OK]
Common Mistakes:
MISTAKES
  • Thinking all columns must be unique
  • Believing GROUP BY sorts data
  • Assuming aggregation speeds queries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes