MIN
Overview
MIN()
is a function that returns the minimum 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:
MIN()
with a single expression
For example, you might want to know what is the lowest rating of all stored movies:
MIN()
with GROUP BY
clause
In this example, we will use a GROUP BY
clause to group the movie categories, then use MIN()
function to get the lowest rating in each movie category and arrange the results in ascending order.
By running the code above, we will get the following output: