Syntax
COUNT([DISTINCT | ALL] expr)
Purpose
COUNT() returns the number of non-NULL values in rows retrieved by using the SELECT statement. If no such rows are found, COUNT() returns 0. 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.
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