Bird
0
0

Find the error in this query:

medium📝 Debug Q7 of 15
SQL - GROUP BY and HAVING
Find the error in this query:

SELECT department, MAX(salary) FROM employees GROUP BY employee_id;
AMAX() cannot be used with GROUP BY
Bdepartment cannot be selected with MAX()
CMissing WHERE clause before GROUP BY
DGROUP BY column does not match selected non-aggregated column
Step-by-Step Solution
Solution:
  1. Step 1: Check GROUP BY and SELECT columns

    Non-aggregated columns in SELECT must appear in GROUP BY; here department is selected but grouped by employee_id.
  2. Step 2: Identify mismatch

    This mismatch causes error because department is not grouped or aggregated.
  3. Final Answer:

    GROUP BY column does not match selected non-aggregated column -> Option D
  4. Quick Check:

    Non-aggregated SELECT columns must be in GROUP BY [OK]
Quick Trick: GROUP BY columns must include all non-aggregated SELECT columns [OK]
Common Mistakes:
MISTAKES
  • Selecting columns not in GROUP BY or aggregate
  • Assuming MAX() replaces GROUP BY
  • Missing WHERE clause confusion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes