Skip to main content

Overview

MAX() is a function that returns the maximum value from a set of records.

Syntax

The syntax for this function is as follows:
This function’s output data type will always be the same as the input one, however it returns NULL if there are no records or input consists of NULL values and it also returns NaN if the input contains a NaN.

Examples

For the needs of this section, we will create a movies table that stores movie details, such as movie’s title, category, and IMDb rating.
By running the above query, we will get the following output:

MAX() with a single expression

For example, you might want to know what is the highest rating among all stored movies:

MAX() with GROUP BY clause

We use a MAX() function in this example to get the highest rating in each movie category and the results are ordered by the rating in ascending order.
By running the above code, we will get the highest rating from a group of movieCategory as shown below: