Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SQL is there a difference between count(*) and count(<fieldname>)

Tags:

sql

Pretty self explanatory question. Is there any reason to use one or the other?

like image 435
Spencer Ruport Avatar asked Jan 11 '09 22:01

Spencer Ruport


2 Answers

Count(*) counts all records, including nulls, whereas Count(fieldname) does not include nulls.

like image 146
Fionnuala Avatar answered Oct 03 '22 22:10

Fionnuala


Select count(*) selects any row, select count(field) selects rows where this field is not null.

like image 22
Otávio Décio Avatar answered Oct 03 '22 22:10

Otávio Décio