Arguments to the COUNT Functions

The COUNT function accepts as its argument the same expressions that are allowed in the argument list of other built-in aggregate functions, as well as the asterisk (*) notation that only COUNT supports. The following categories of built-in expressions are supported as the argument to COUNT, as illustrated in the following examples:

You can also use the asterisk (*) character, or a column name, or a column name with the ALL, DISTINCT, or UNIQUE aggregate scope qualifiers as the argument to the COUNT function to retrieve different types of information about a table. The table below summarizes the meaning of each of the following forms of the COUNT function with an asterisk or column name argument.
COUNT Function Description
COUNT (*) Returns the number of rows that satisfy the query. If you do not specify a WHERE clause, this function returns the total number of rows in the table.
COUNT (DISTINCT) or COUNT (UNIQUE) Returns the number of unique non-NULL values in the specified column
COUNT (column) or COUNT (ALL column) Returns the total number of non-NULL values in the specified column

Some examples can help to show the differences among the various forms of the COUNT function that reference a column. Most of the following examples query against the ship_instruct column of the orders table in the stores_demo demonstration database. For information on the schema of the orders table and the data values in the ship_instruct column, see the description of the demonstration database in the HCL Informix® Guide to SQL: Reference.


Copyright© 2021 HCL Technologies Limited