You are viewing an older version of this section. View current production version.
Join the SingleStore Community Today
Get expert advice, develop skills, and connect with others.

COUNT

Aggregate function. Counts the number of rows passed in. If the value of a given item is NULL, the row is not counted.

Syntax

COUNT ( [DISTINCT] expression )

Arguments

  • DISTINCT: optional keyword. If present, will count the number of unique values.
  • expression: any expression. This may be a column name, the result of another function, or a math operation. The special operator “*” is also allowed, to indicate pure row counting.

Return Type

An integer.

Examples

memsql> select count(*) from people;
+----------+
| count(*) |
+----------+
|     5000 |
+----------+

memsql> select count(middle_name) as middles from people;
+----------+
|  middles |
+----------+
|     1238 |
+----------+

memsql> select count(DISTINCT middle_name) as middles from people;
+----------+
|  middles |
+----------+
|      213 |
+----------+