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.
views:
205answers:
4
+19
A:
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.
Learning
2009-03-17 09:48:08
+4
A:
See MSDN
Count(phoneNo) will return the number of records where phoneNo is not null. Count(*) returns the number or rows regardless.
CJM
2009-03-17 09:49:18
+1: Quote the documentation.
S.Lott
2009-03-17 09:57:11
+2
A:
COUNT(*) will count every row. COUNT(yourColumn) won't include rows where yourColumn is NULL.
For example, if there are 20 rows in your table and the phoneNumber column is NULL in 5 of those rows, then COUNT(*) will return 20 whereas COUNT(phoneNumber) will return 15.
LukeH
2009-03-17 09:49:23
+7
A:
On the other hand you can count distinct values. count(distinct firstName) may deliver a different result as count(distinct phoneNumber) and both may be different to count().
Mork0075
2009-03-17 09:50:53