Watch the 7.3 Webinar On-Demand
This new release brings updates to Universal Storage, query optimization, and usability that you won’t want to miss.

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

SELECT COUNT(*) FROM people;
+----------+
| COUNT(*) |
+----------+
|     5000 |
+----------+

SELECT COUNT(middle_name) AS middles FROM people;
+----------+
|  middles |
+----------+
|     1238 |
+----------+

SELECT COUNT(DISTINCT middle_name) AS middles FROM people;
+----------+
|  middles |
+----------+
|      213 |
+----------+