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?
0 Answers