FirebirdSQL logo

COUNT()

Counts non-NULL values

Result type

BIGINT

Syntax
COUNT ([ALL | DISTINCT] <expr> | *)
Table 1. COUNT Function Parameters
Parameter Description

expr

Expression.It may contain a table column, a constant, a variable, an expression, a non-aggregate function or a UDF that returns a numeric data type.Aggregate functions are not allowed as expressions

COUNT returns the number of non-null values in a group.

  • ALL is the default: it counts all values in the set that are not NULL.

  • If DISTINCT is specified, duplicates are excluded from the counted set.

  • If COUNT (*) is specified instead of the expression expr, all rows will be counted.COUNT (*) — 

    • does not accept parameters

    • cannot be used with the keyword DISTINCT

    • does not take an expr argument, since its context is column-unspecific by definition

    • counts each row separately and returns the number of rows in the specified table or group without omitting duplicate rows

    • counts rows containing NULL

  • If the result set is empty or contains only NULL in the specified column(s), the returned count is zero.

COUNT Examples

SELECT
  dept_no,
  COUNT(*) AS cnt,
  COUNT(DISTINCT name) AS cnt_name
FROM employee
GROUP BY dept_no
See also

SELECT.