Returns the highest value in an expression.
max(expression)
is a column name, constant, function, any combination of column names, constants, and functions connected by arithmetic or bitwise operators, or a subquery.
Returns the maximum value in the discount column of the salesdetail table as a new column:
select max(discount) from salesdetail
-------------------- 62.200000
Returns the maximum value in the discount column of the salesdetail table as a new row:
select discount from salesdetail compute max(discount)
max, an aggregate function, finds the maximum value in a column or expression. For general information about aggregate functions, see “Aggregate functions”.
max can be used with exact and approximate numeric, character, and datetime columns. It cannot be used with bit columns. With character columns, max finds the highest value in the collating sequence. max ignores null values. max implicitly converts char datatypes to varchar, unichar datatypes to univarchar, stripping all trailing blanks.
unichar data is collated according to the default Unicode sort order.
Adaptive Server goes directly to the end of the index to find the last row for max when there is an index on the aggregated column, unless:
The expression not a column
The column is not the first column of an index
There is another aggregate in the query
There is a group by or where clause
SQL92 – Compliance level: Transact-SQL extension.
Any user can execute max.
Commands compute clause, group by and having clauses, select, where clause