Syntax
COUNT([DISTINCT | ALL] expr)
Purpose
Returns the number of non-NULL values in the rows retrieved by the SELECT statement. If no matching rows are found, it returns 0. The DISTINCT option can be used to return the number of distinct values of expr.
COUNT(*) is slightly different in that it returns the number of retrieved rows, regardless of whether they contain NULL values.
Examples
obclient> SELECT * FROM test;
+----+------+------+
| id | ip | ip2 |
+----+------+------+
| 1 | 4 | NULL |
| 3 | 3 | NULL |
| 4 | 3 | NULL |
+----+------+------+
3 rows in set
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
