Hitachi

Hitachi Advanced Database SQL Reference


8.15.3 LEAST

Returns the smallest value among the specified target data items.

In addition to comparing numeric data items, you can also compare character string data items and datetime data items.

Organization of this subsection

(1) Specification format

scalar-function-LEAST ::= LEAST(target-data-1[,target-data-2]...)
 
  target-data-1 ::= value-expression
  target-data-2 ::= value-expression

(2) Explanation of specification format

target-data-1, target-data-2, ...:

Specifies the numeric data whose smallest value is to be determined.

The following rules apply:

  • Specify the target data in the form of a value expression. For details about value expressions, see 7.20 Value expression.

  • A maximum of 255 target data items can be specified.

  • The data types that can be specified for the target data are numeric data, character string data, and datetime data.

  • You must specify data types that can be compared in target-data-1, target-data-2, .... For details about data types that can be compared, see (1) Data types that can be compared in 6.2.2 Data types that can be converted, assigned, and compared. However, note the following exceptions:

    DATE type data cannot be compared to character string data (even to the predefined input representation of a date).

    TIME type data cannot be compared to character string data (even to the predefined input representation of a time).

    TIMESTAMP type data cannot be compared to character string data (even to the predefined input representation of a time stamp).

    For details about predefined input representations, see 6.3.3 Predefined character-string representations.

  • You cannot specify a dynamic parameter by itself for target-data-1.

  • If a dynamic parameter is specified by itself for target-data-2, or later, the data type of target-data-1 is assumed for the data type of the dynamic parameter.

(3) Rules

  1. The data type and data length of the execution result are determined according to the rules described in 7.20.2 Data types of the results of value expressions.

  2. The NOT NULL constraint does not apply to the value of the execution result (the null value is allowed).

  3. If any of the specified target data has a null value, the execution result will be a null value.

(4) Example

Example:

Determine the smallest value among the values of columns C1 to C4 in table T1.

SELECT LEAST("C1","C2","C3","C4") FROM "T1"

[Figure]