Counting Rows with COUNT()
Use the aggregate function COUNT() to count the number of rows in a set of values. COUNT() has two forms:
COUNT(expr) returns the number of rows in which expr is not null.
COUNT(*) returns the count of all rows in a set, including nulls and duplicates.
To count non-null rows:
expr is a column name, literal, or expression. The result is an integer greater than or equal to zero.
To count all rows, including nulls:
COUNT(*) returns an integer greater than or equal to zero.
Listing 6.5 and Figure 6.5 show some queries that involve COUNT(expr) and COUNT(*). The three queries count rows in the table titles and are identical except for the WHERE clause. The row counts in the first query ...