MIN

The MIN aggregate function returns the minimum value in a set of values in a group.

Read syntax diagramSkip visual syntax diagramMIN( ALLDISTINCT expression )
expression
The argument values can be any built-in data type other than a DataLink or XML.

The data type and length attribute of the result are the same as the data type and length attribute of the argument values. When the argument is a string, the result has the same CCSID as the argument. The result can be null.

If a collating sequence other than *HEX is in effect when the statement that contains the MIN function is executed and the arguments are SBCS data, mixed data, or Unicode data, then the result is obtained by comparing weighted values for each value in the set.

The function is applied to the set of values derived from the argument values by the elimination of null values.

If the set of values is empty, the result is a null value. Otherwise, the result is the minimum value in the set.

The specification of DISTINCT has no effect on the result and is not advised.

Notes

Results involving DECFLOAT special values: If the data type of the argument is decimal floating-point and positive or negative Infinity, sNaN, or NaN is found, the minimum value is determined using decimal floating-point ordering rules. See Numeric comparisons. If multiple representations of the same decimal floating-point value are found (for example, 2.00 and 2.0), it is unpredictable which representation will be returned.

Examples

  • Using the EMPLOYEE table, set the host variable COMM_SPREAD (DECIMAL(7,2)) to the difference between the maximum and minimum commission (COMM) for the members of department (WORKDEPT) ‘D11'.
         SELECT MAX(COMM) - MIN(COMM)
           INTO :COMM_SPREAD
           FROM EMPLOYEE
           WHERE WORKDEPT  = 'D11'
    Results in COMM_SPREAD being set to 1118 (that is, 2580 - 1462).
  • Using the PROJECT table, set the host variable FIRST_FINISHED (CHAR(10)) to the estimated ending date (PRENDATE) of the first project scheduled to be completed.
         SELECT MIN(PRENDATE)
           INTO :FIRST_FINISHED
           FROM PROJECT
    Results in FIRST_FINISHED being set to ‘1982-09-15'.