MAX( )

From InterBase

Go Up to Statement and Function Reference (Language Reference Guide)


Retrieves the maximum value in a column. Available in gpre, DSQL, and isql.

MAX ([ALL] val | DISTINCT val)
Argument Description

ALL

Searches all values in a column

DISTINCT

Eliminates duplicate values before finding the largest

<val>

A column, constant, host-language variable, expression, non-aggregate function, or UDF

Description: MAX() is an aggregate function that returns the largest value in a specified column, excluding NULL values. If the number of qualifying rows is zero, MAX() returns a NULL value.

When MAX() is used on a CHAR, VARCHAR, or Blob text column, the largest value returned varies depending on the character set and collation in use for the column. A default character set can be specified for an entire database with the DEFAULT CHARACTER SET clause in CREATE DATABASE, or specified at the column level with the COLLATE clause in CREATE TABLE.

Example: The following embedded SQL statement demonstrates the use of SUM(), AVG(), MIN(), and MAX():

EXEC SQL
SELECT SUM (BUDGET), AVG (BUDGET), MIN (BUDGET), MAX (BUDGET)
FROM DEPARTMENT
WHERE HEAD_DEPT = :head_dept
INTO :tot_budget, :avg_budget, :min_budget, :max_budget;

See Also