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 Transact-SQL Users Guide.
You can use max with exact and approximate numeric, character, and datetime columns; you cannot use it 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, and unichar datatypes to univarchar, stripping all trailing blanks.
unichar data is collated according to the default Unicode sort order.
max preserves the trailing zeros in varbinary data.
max returns a varbinary datatype from queries on binary data.
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.
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute max.
Commands compute clause, group by and having clauses, select, where clause