Bird
0
0

Identify the error in this SQL query:

medium📝 Debug Q14 of 15
SQL - Advanced Query Patterns
Identify the error in this SQL query:
SELECT name, age FROM users WHERE age > 18 GROUP BY name;
AThe query is correct as written.
BWHERE clause cannot be used with GROUP BY.
CSELECT must include only columns in GROUP BY.
DGROUP BY should include all selected columns or use aggregation.
Step-by-Step Solution
Solution:
  1. Step 1: Review SELECT and GROUP BY rules

    When using GROUP BY, all selected columns must be grouped or aggregated.
  2. Step 2: Check the query columns

    The query selects name and age but only groups by name, so age is neither grouped nor aggregated.
  3. Final Answer:

    GROUP BY should include all selected columns or use aggregation. -> Option D
  4. Quick Check:

    All selected columns must be in GROUP BY or aggregated [OK]
Quick Trick: All selected columns must be grouped or aggregated [OK]
Common Mistakes:
  • Thinking WHERE conflicts with GROUP BY
  • Ignoring missing aggregation for non-grouped columns
  • Assuming query is correct without aggregation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes