Interview Q&A / SQL & DBMS

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column)?

SHORT ANSWER

COUNT(*) counts all rows, COUNT(column) counts rows where that column is not NULL, and COUNT(DISTINCT column) counts the different non-NULL values.

Explain it simply

Imagine an attendance sheet with a column for mobile number. COUNT(*) counts every student on the sheet. COUNT(mobile) counts only students who wrote a number. COUNT(DISTINCT mobile) counts the different numbers, so two siblings sharing one phone count once.

Example

Table students:

idnamemobile
1Asha98100
2RaviNULL
3Neha98100
4Imran97000
sql
SELECT COUNT(*)               AS all_rows,      -- 4
       COUNT(mobile)          AS with_mobile,   -- 3
       COUNT(DISTINCT mobile) AS unique_mobile  -- 2
FROM students;
  • 4 rows exist.
  • Ravi's NULL is skipped, so 3.
  • 98100 appears twice and counts once, so 2 distinct values.

COUNT(1) behaves the same as COUNT(*); modern optimizers treat them identically.

What to say in the interview

"COUNT(*) counts rows regardless of NULLs. COUNT(col) ignores NULLs in that column. COUNT(DISTINCT col) also removes duplicates. On an empty table COUNT returns 0, while SUM, AVG and MAX return NULL."

Common mistakes

  • Using COUNT(column) to count rows and silently losing the NULL ones.

#sql#aggregate#count

Related questions

Practise more SQL & DBMS questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open SQL & DBMS quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.