4. Elements of OpenSQL Statements : Functions : Aggregate Functions : Count(*) Function
 
Share this page                  
Count(*) Function
Count can take the wildcard character, *, as an argument. This character is used to count the number of rows in a result table, including rows that contain nulls. For example, the statement:
select count(*)
    from employee
    where dept = 23;
counts the number of employees in department 23. The asterisk (*) argument cannot be qualified with all or distinct.
Because count(*) counts rows rather than columns, count(*) does not ignore nulls. Consider the following table:
Name
Exemptions
Smith
0
Jones
2
Tanghetti
4
Fong
Null
Stevens
Null
Running
count(exemptions)
returns the value of 3, whereas
count(*)
returns 5.
Except count, if the argument to an aggregate function evaluates to an empty set, the function returns a null. The count function returns a zero.