Syntax
COUNT([DISTINCT ALL] expr)
Purpose
You can call this function to return the number of non-NULL values in rows retrieved by using the SELECT statement. If no such rows are found, 0 is returned. You can use the DISTINCT option to return the number of distinct values of expr.
This function differs from COUNT(*) in that COUNT(*) returns the number of retrieved rows, regardless of whether the rows contain NULL values.
Examples
obclient> SELECT * FROM test;
+----+------+------+
id ip ip2
+----+------+------+
1 4 NULL
3 3 NULL
4 3 NULL
+----+------+------+
3 rows in set (0.00 sec)
obclient> SELECT COUNT(ip2), COUNT(ip), COUNT(DISTINCT(ip)), COUNT(*) FROM test;
+------------+-----------+---------------------+----------+
count(ip2) count(ip) count(distinct(ip)) count(*)
+------------+-----------+---------------------+----------+
0 3 2 3
+------------+-----------+---------------------+----------+
1 row in set (0.00 sec)