Bird
0
0

Given the table employees with the column department containing values: ['HR', 'IT', NULL, 'IT', 'HR', 'Finance', NULL], what is the result of the query SELECT COUNT(DISTINCT department) FROM employees;?

medium📝 query result Q13 of 15
SQL - Aggregate Functions
Given the table employees with the column department containing values: ['HR', 'IT', NULL, 'IT', 'HR', 'Finance', NULL], what is the result of the query SELECT COUNT(DISTINCT department) FROM employees;?
A3
B5
C7
D4
Step-by-Step Solution
Solution:
  1. Step 1: Identify distinct non-NULL values in department

    The distinct non-NULL values are 'HR', 'IT', and 'Finance'. That's 3 unique values.
  2. Step 2: Understand COUNT(DISTINCT) behavior

    COUNT(DISTINCT column) counts unique non-NULL values only, so NULLs are excluded.
  3. Step 3: Count distinct values

    There are 3 distinct non-NULL values, so the count is 3.
  4. Final Answer:

    3 -> Option A
  5. Quick Check:

    COUNT(DISTINCT) excludes NULLs [OK]
Quick Trick: COUNT(DISTINCT) counts unique non-NULL values only [OK]
Common Mistakes:
MISTAKES
  • Including NULL as a distinct value
  • Counting total rows instead of distinct
  • Confusing COUNT(*) with COUNT(DISTINCT)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes