Bird
0
0

Identify the error in this SQL query:

medium📝 Debug Q14 of 15
SQL - GROUP BY and HAVING
Identify the error in this SQL query:
SELECT department, COUNT(*) FROM employees;
AThe query is correct and will run without errors.
BCOUNT(*) cannot be used without WHERE clause.
Cdepartment cannot be selected without aggregation.
DMissing GROUP BY clause for the department column.
Step-by-Step Solution
Solution:
  1. Step 1: Check SELECT with aggregation

    COUNT(*) is an aggregate but department is not aggregated or grouped.
  2. Step 2: Identify missing GROUP BY

    To select department with COUNT(*), GROUP BY department is required.
  3. Final Answer:

    Missing GROUP BY clause for the department column. -> Option D
  4. Quick Check:

    Non-aggregated columns need GROUP BY [OK]
Quick Trick: Non-aggregated columns need GROUP BY [OK]
Common Mistakes:
MISTAKES
  • Ignoring missing GROUP BY
  • Thinking COUNT(*) needs WHERE
  • Assuming query runs without error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes