Bird
0
0

A query:

medium📝 Debug Q7 of 15
SQL - GROUP BY and HAVING
A query:
SELECT Category, COUNT(*) FROM Products GROUP BY Category HAVING Category IS NULL;
returns zero rows, but you know some rows have NULL Category. What is the issue?
AHAVING filters groups after grouping; NULL groups exist but condition is wrong.
BHAVING clause cannot compare NULL with = or IS NULL correctly.
CNULL groups are excluded by default in GROUP BY.
DCOUNT(*) excludes NULL rows.
Step-by-Step Solution
Solution:
  1. Step 1: Understand HAVING with NULL groups

    HAVING filters groups after grouping; condition Category IS NULL should match NULL group.
  2. Step 2: Identify why zero rows returned

    Some SQL engines treat NULL in HAVING differently; better to use COALESCE or check data carefully.
  3. Final Answer:

    HAVING filters groups after grouping; NULL groups exist but condition is wrong. -> Option A
  4. Quick Check:

    HAVING filters groups; NULL condition may behave unexpectedly [OK]
Quick Trick: HAVING filters groups; test NULL conditions carefully [OK]
Common Mistakes:
MISTAKES
  • Assuming NULL groups are excluded by GROUP BY
  • Misusing HAVING with NULL comparisons
  • Thinking COUNT(*) ignores NULL rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes