MAX() function returns the maximum value from a set of records.
The input and return types we support can be seen in the table below.
✅ The return will be the same as the data type used as the input values.
- Returns NULL if there are no input rows or NULL values.
- Returns NaN if the input contains a NaN.
For the MAX() examples, we will use the same sample table as in the MIN() section.
We have a movies table that stores the movie details, such as the movie’s title, category, and IMDb rating.
The above query will show the following table:
For example, you might want to know what is the highest rating among all stored movies:
It will return the following output:
We use a MAX() for this example to get the highest rating in each movie category.
It will display the highest rating from a group of movieCategory as shown below:
In this example, we want to get a movie that has the highest rating by using a subquery:
It will return the following result: