Bird
0
0

What is wrong with this query?

medium📝 Debug Q14 of 15
SQL - GROUP BY and HAVING
What is wrong with this query?
SELECT department, employee_name, COUNT(*) FROM employees GROUP BY department;
AYou cannot select employee_name without grouping by it or using an aggregate function.
BCOUNT(*) cannot be used with GROUP BY.
CGROUP BY must come before SELECT.
DThe query is correct and will run without errors.
Step-by-Step Solution
Solution:
  1. Step 1: Check columns in SELECT with GROUP BY

    When using GROUP BY on 'department', all selected columns must be grouped or aggregated.
  2. Step 2: Identify the error

    'employee_name' is neither grouped nor aggregated, causing a syntax error.
  3. Final Answer:

    You cannot select employee_name without grouping by it or using an aggregate function. -> Option A
  4. Quick Check:

    Non-grouped columns must be aggregated [OK]
Quick Trick: All selected columns must be grouped or aggregated [OK]
Common Mistakes:
MISTAKES
  • Selecting non-grouped columns without aggregation
  • Thinking COUNT(*) is invalid with GROUP BY
  • Misplacing GROUP BY clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes