Declaration
COUNT([DISTINCT | ALL] expr)
Description
Returns the number of non-NULL values in the rows retrieved by the SELECT statement. If no matching rows are found, returns 0. The DISTINCT option can be used to return the number of distinct values of expr.
COUNT(*) returns the number of rows retrieved, 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