Explain the purpose of the MAX() and MIN() functions in SQL and provide examples.
Explain the purpose of the MAX() and MIN() functions in SQL and provide examples.
349
30-Jun-2023
Updated on 01-Jul-2023
Aryan Kumar
01-Jul-2023Sure. The MAX() and MIN() functions in SQL are aggregate functions that are used to return the maximum and minimum values of a column, respectively. The syntax for the MAX() and MIN() functions is:
SQL
column_nameis the name of the column that you want to return the maximum or minimum value of.The MAX() and MIN() functions can be used in a variety of ways, such as:
For example, the following query will return the maximum price of all products in the
productstable:SQL
The following query will return all products in the
productstable where the price is less than the maximum price:SQL
The following query will return the minimum age of all customers in the
customerstable:SQL
The following query will return all customers in the
customerstable where the age is greater than the minimum age:SQL
The MAX() and MIN() functions are powerful tools that can be used to perform a variety of tasks with your SQL data.