This table stores information about cosmetic products in three categories (the column category): hair, face, and eye. Here is the syntax of the MAX() function:īefore we will start to analyze MIN() and MAX() use cases, let’s look at the data we’ll be using in the table cosmetics: id It is a scalar function that returns one value. The values can come from a column or as the result of an expression that returns a numeric value or values. The difference is that it returns the largest (maximum) value. Like MIN(), MAX() is an aggregate function that returns a numeric value from a set. It’s important that the values are numeric, because the function finds the minimum value among them. The syntax of the MIN() function is presented below:Īs you see, this function takes one argument – a column or an expression with numeric values. (Note: The column can come from a table or a view.) It is a scalar function that returns one numeric value. The values can come from a numeric column or as the result of an expression returning a numeric value. It returns the smallest value in a set of values. A Beginner’s Guide to SQL Aggregate Functions discusses all of them in detail this article focuses on only two of these functions: MIN() and MAX().įirst, let’s talk about the MIN() function. These aggregate functions compute calculations on numerical data. The SQL standard is supported by most relational database engines and includes several aggregate functions.
In this article, I will explain what each function does and discuss several use cases. They are very useful among many data professionals because they allow us to resolve a lot of business problems.
It’s difficult to imagine SQL without the MIN() and MAX() aggregate functions. What are the SQL MIN() and MAX() functions? When should you use them as aggregate functions, and when should you use them with window functions? We explain using practical examples.