Function group: aggregate function
MAX() determines the largest value in a set of values. NULL values are ignored. Comparing alphanumeric values, national values, numeric values and time values is described in section "Comparison of two rows".
MAX ([ALL | DISTINCT ]
expression )
ALL / DISTINCT
ALL or DISTINCT can be specified but has no effect on the result.
expression
Numeric expression, alphanumeric expression, national expression or time value expression (see section "Aggregate functions" for information on restrictions).
Result
If the set of values returned by expression is empty, the result or the result for this group is the NULL value.
Otherwise:
Without GROUP BY clause:
Determines the largest value in the set of values returned by expression (see "Calculating aggregate functions").
With GROUP BY clause:
Returns the largest value of each group.
Data type: like expression
Examples
SELECT without GROUP BY:
Query the highest service price for order 211 in the SERVICE table (result: 1200):
SELECT MAX(service_price) FROM service WHERE order_num=211
SELECT with GROUP BY:
Determine the highest service price for each order number:
SELECT order_num, MAX(service_price) FROM service GROUP BY order_num order_num 200 1500 211 1200 250 1200