Bird
0
0

Identify the error in this query:

medium📝 Debug Q14 of 15
SQL - GROUP BY and HAVING
Identify the error in this query:
SELECT department, role, COUNT(*) FROM employees GROUP BY department;
AMissing role column in GROUP BY clause
BCOUNT(*) cannot be used with GROUP BY
Cdepartment should not be in GROUP BY
DSELECT must include only aggregated columns
Step-by-Step Solution
Solution:
  1. Step 1: Check SELECT columns vs GROUP BY columns

    Columns in SELECT that are not aggregated must appear in GROUP BY. Here, role is in SELECT but missing in GROUP BY.
  2. Step 2: Understand aggregation rules

    COUNT(*) is valid, but all non-aggregated columns must be grouped to avoid errors.
  3. Final Answer:

    Missing role column in GROUP BY clause -> Option A
  4. Quick Check:

    All non-aggregated SELECT columns must be in GROUP BY [OK]
Quick Trick: Include all non-aggregated SELECT columns in GROUP BY [OK]
Common Mistakes:
MISTAKES
  • Ignoring missing columns in GROUP BY
  • Thinking COUNT(*) is invalid with GROUP BY
  • Assuming GROUP BY only needs one column

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes