October 08, 2007

Count(*) Vs Count('column')

Count(*):
1. COUNT(*) returns the number of rows that match the search conditions specified in the query without eliminating duplicates.
 SELECT COUNT(*)
FROM titles
2.COUNT(*) can be combined with other aggregate functions.
 SELECT COUNT(*), AVG(price)
FROM titles
WHERE advance > $1000


SELECT COUNT(DISTINCT city)
FROM authors
Remark:

COUNT(*) returns the number of items in a group, including NULL values and duplicates.

COUNT(ALL expression) evaluates expression for each row in a group and returns the number of nonnull values.

COUNT(DISTINCT expression) evaluates expression for each row in a group and returns the number of unique, nonnull values.


No comments: