LEAST Function

Description

The LEAST function compares more than one expression specified as parameters and returns the smallest value. If only one expression has been specified, the expression is returned because there is no expression to be compared with.

Therefore, more than one expression that are specified as parameters must be of the type that can be compared with each other. If the types of the specified parameters are identical, so are the types of the return values; if they are different, the type of the return value becomes a convertible common data type.

That is, the LEAST function compares the values of column 1, column 2 and column 3 in the same row and returns the smallest value while the MIN function compares the values of column in all result rows and returns the smallest value. 

Syntax

LEAST( expression [, expression]* )

Example

The following example shows how to retrieve the number of every medals and the lowest number that Korea won (demodb).

SELECT gold, silver , bronze, LEAST(gold, silver, bronze) FROM participant

WHERE nation_code = 'KOR';

         gold       silver       bronze  least(gold, silver, bronze)

====================================================================

            9           12            9                            9

            8           10           10                            8

            7           15            5                            5

           12            5           12                            5

           12           10           11                           10