COUNT()

Aggregate. Returns the number of rows containing a non-NULL value in a particular column.

Syntax

COUNT( { [DISTINCT] expression } | * )
Parameter

expression

Note that you cannot use DISTINCT with an XML column.

Data Types

Return

expression

Integer

Integer

Long

Float

Interval

Timestamp

String

Boolean

Blob

XML

Usage

COUNT counts the number of rows returned by a query. COUNT(*) returns the number of rows, regardless of the value of those rows and including duplicate values. COUNT(expression) returns the number of non-NULL values for that expression returned by the query. For example, COUNT(column_A) returns the number of non-NULL values in column_A. If all input rows submitted to COUNT have a value of NULL, COUNT returns a value of 0. COUNT never returns NULL.

Examples

INSERT INTO OutStream
SELECT COUNT(*)
FROM DeviceExceptions;
INSERT INTO OutStream
SELECT COUNT(commission_pct)
FROM SalesOrders;
INSERT INTO OutStream
SELECT COUNT(DISTINCT province_id)
FROM Contestants;