0

Why COUNT() doesn’t count NULL values in MySQL?

Hey everyone 👋 I’m learning SQL and got a small doubt. COUNT() counts rows, but it skips NULL values. Why does COUNT() ignore NULL? And also, how does COUNT(IF(...)) work when there are NULLs? Here’s a small example 👇 CREATE TABLE students ( id INT, marks INT ); INSERT INTO students VALUES (1, 90), (2, NULL), (3, 80); SELECT COUNT(marks) AS count_marks, COUNT(*) AS count_rows FROM students; Output: count_marks → 2 count_rows → 3 Can someone explain why COUNT(marks) = 2 instead of 3?

7th Oct 2025, 6:12 AM
SAI KIRAN TALASILA
SAI KIRAN TALASILA - avatar
0 Answers