Bird
0
0

Find the issue in this query: SELECT COUNT(*) FROM orders WHERE discount IS NOT NULL AND discount = NULL;

medium📝 Debug Q7 of 15
SQL - Aggregate Functions
Find the issue in this query: SELECT COUNT(*) FROM orders WHERE discount IS NOT NULL AND discount = NULL;
ACOUNT(*) cannot be used with WHERE
BUsing both IS NOT NULL and = NULL together is contradictory
CMissing GROUP BY clause
Ddiscount column does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Review WHERE conditions

    discount IS NOT NULL and discount = NULL cannot both be true; = NULL is invalid syntax.
  2. Step 2: Validate COUNT(*) usage

    COUNT(*) with WHERE is valid; no GROUP BY needed; discount column assumed to exist.
  3. Final Answer:

    Using both IS NOT NULL and = NULL together is contradictory -> Option B
  4. Quick Check:

    NULL comparisons must use IS NULL or IS NOT NULL [OK]
Quick Trick: NULL checks must use IS NULL or IS NOT NULL only [OK]
Common Mistakes:
MISTAKES
  • Using '=' to compare NULL
  • Confusing logical conditions in WHERE
  • Assuming COUNT(*) needs GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes