Bird
0
0

Find the mistake in this query:

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

SELECT city, COUNT(*) FROM customers GROUP BY city ORDER BY city_name ASC;
AMissing WHERE clause before GROUP BY
BCOUNT(*) cannot be used without alias
CGROUP BY must include COUNT(*)
DORDER BY uses a column 'city_name' not in SELECT or GROUP BY
Step-by-Step Solution
Solution:
  1. Step 1: Check ORDER BY column

    ORDER BY references 'city_name' which is not in SELECT or GROUP BY.
  2. Step 2: Identify error

    ORDER BY must use columns from SELECT or GROUP BY; 'city_name' causes error.
  3. Final Answer:

    ORDER BY uses a column 'city_name' not in SELECT or GROUP BY -> Option D
  4. Quick Check:

    ORDER BY columns must be in SELECT or GROUP BY [OK]
Quick Trick: ORDER BY columns must exist in SELECT or GROUP BY [OK]
Common Mistakes:
MISTAKES
  • Ordering by columns not selected or grouped
  • Assuming COUNT(*) needs alias
  • Adding unnecessary WHERE clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes