COUNT(column) ignores NULLs: counts differ from COUNT(*)
COUNT(col) counts only non-NULL values, while COUNT(*) counts rows, so totals don't match.
COUNT(*) vs COUNT(column) different resultsCOUNT ignores NULL valuesAVG ignores NULLaggregate function eliminated NULL valueWarning: Null value is eliminated by an aggregate or other SET operation Meaning
Aggregates (SUM, AVG, COUNT(col)) skip NULLs, and AVG is computed over non-NULL rows only. Use COUNT(*) for rows, COUNT(DISTINCT col) for unique non-null values, and COALESCE when NULL should count as 0.
Common causes
- Nullable column inside COUNT
- AVG ignoring NULL rows
- LEFT JOIN producing NULLs in the counted column
- DISTINCT confusion
- Expecting NULL to be zero
⚡ Quick fix
- Use
COUNT(*)to count rows COALESCE(col, 0)before aggregating- Check the nullable columns in the query
Detailed fix by platform
SQL
SELECT COUNT(*) AS rows_, COUNT(email) AS with_email, AVG(COALESCE(score, 0)) AS avg_all FROM users;
How to diagnose
- Column — Nullable?
- COUNT — (*) or (col)?
- AVG — Over non-NULL only?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- = NULL WHERE col = NULL returns no rows (use IS NULL)
- 515 SQL Server Msg 515: Cannot insert the value NULL into column 'X', table 'Y'; column does not allow nulls
- 8120 SQL Server Msg 8120: Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
Most viewed in SQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026