Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the count() function require a parameter?

Tags:

sql-server

The count() function counts rows, and is very often used as count(*). If I had a table with phoneNo and firstName, count(phoneNumber) returns the same number as count(*). All columns are always present, if not populated, in each row.

like image 603
ProfK Avatar asked Mar 17 '09 09:03

ProfK


1 Answers

There is a subtle difference.

If you specify a field , count(fieldname) will count records which have non null values for the field. count(*) will give you total rows.

like image 100
Learning Avatar answered Oct 03 '22 13:10

Learning