COUNT Returns a count of values in the data set.

Syntax

COUNT( [ DISTINCT | ALL ] columnName)
or
COUNT(*)

Arguments

  • DISTINCT \| ALL: Specifying the DISTINCT keyword excludes duplicate values from the calculation.
    • Specifying ALL explicitly includes all values, including duplicates.
    • ALL is the default behavior and is not required. </ul>
    • columnName: A column name from the data set.
    • \*: Counts all values.
    • </ul> ## Returns ## An integer value. ## Additional Information ## * Multiple aggregate functions can be combined in the same query, so long as they comply with the following: * Only one DISTINCT keyword can be used per query. This means that if you are submitting both an [AVG function](/avg_aggregate_function.html) and [SUM function](/sum_aggregate_function.html) in the same query, only one can include the DISTINCT function, even though DISTINCT is supported with each function if submitted individually. ## Examples ## ```sql SELECT COUNT(*) FROM MYSQL.inventory.orders WHERE orderDate>='2012-01-01' AND orderDate<='2012-12-31' SELECT COUNT(countColumn) FROM (VALUES (1), (2), (3)) AS myTable (countColumn); -- Returns 3 SELECT COUNT(DISTINCT countColumn) FROM (VALUES (1), (2), (3)) AS myTable (countColumn); -- Returns 2 ```