MAX
Given an input set of values, MAX returns the maximum value in that set.
Syntax
MAX (expression)
Remarks
• | Expression can be numeric, string, or date-time. |
• | The output type is the same as the input type. |
• | If the input is a CHAR, the output is the highest string in the sorting order. |
• | If the input is date/time, the output is the latest date/time. |
• | If the input is a literal, the output is the same literal. |
• | If the input is a numeric expression, MAX compares the values in algebraic order; that is, large negative numbers are less than small negative numbers, which are less than zero. |
The following table lists the input types that you can use in MAX, and their corresponding output types.
Data Type of expression |
Output Type |
BIGINT, CHAR, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, INTERVAL_DAY, INTERVAL_YEAR, LONGVARCHAR, NULL, NUMERIC, REAL, SMALLINT, TIME, TIMESTAMP, TINYINT, VARCHAR |
Same type as the input type. For example, if the input is of type CHAR, the output is also of type CHAR. |
Example
SELECT MAX (products.UnitPrice) Price,
MAX (orders.OrderDate) Date
FROM /shared/examples/ds_inventory/products products,
/shared/examples/ds_orders/orders orders