(Contents)(Previous)

Determining Minima and Maxima in Character Strings

The functions MIN and MAX that have already been presented for numeric values can also be applied to character strings.

The following statement finds that customer in a city whose name begins with the 'smallest' letter relative to the selected code (ASCII or EBCDIC). If the initial letters are identical, the comparison is extended to the characters following thereafter. To obtain a useful alphabetical order, especially of umlauts, the function MAPCHAR should be used.

SELECT city, MIN (name) min_name

FROM customer

GROUP BY city

The functions GREATEST and LEAST can be used to search the greatest or smallest value from a list of specified values. These functions can be applied to any data type. For example, GREATEST ('Baker', 'Baxter', 'Barker') would produce 'Baxter' as the result, because the 'x' as the first differing letter is the 'greatest' letter in alphabetical order.


(Contents)(Previous)