COUNT

COUNT counts the number of rows in a specified column or table.

Syntax

COUNT (expression)
COUNT (*)

Remarks

The COUNT (expression) syntax specifies a column.
The values in the specified column can be of any data type.
The COUNT (*) syntax returns the count of all rows in a table, including NULL rows.
If the input is a non-NULL set of values, the output is a positive integer.
If the input is NULL, the output is zero.

The following table lists the input types that you can use in COUNT, and their corresponding output types.

Data Type of expression

Output Type

BIGINT, BINARY, BLOB, BOOLEAN, CHAR, CLOB, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, INTERVAL_DAY, INTERVAL_YEAR, LONGVARCHAR, NUMERIC, REAL, SMALLINT, TIME, TIMESTAMP, TINYINT, VARBINARY, VARCHAR

INTEGER

NULL

INTEGER with a value of 0

Example

SELECT COUNT (products.ProductID) CountColumn
FROM /shared/examples/ds_inventory/products products