Day 11 – SQL MIN() and MAX() Functions
In SQL, the
MAX() functions are used to find the minimum and maximum values of a column in a table, respectively. These functions are often used in combination with the
SELECT statement to retrieve summary information about data.
The basic syntax for using the
MAX() functions is as follows:
SELECT MIN(column_name) FROM table_name; SELECT MAX(column_name) FROM table_name;
column_name is the name of the column for which you want to find the minimum or maximum value, and
table_name is the name of the table that contains the column.
For example, suppose you have a table called
sales with columns
sales_amount. If you want to find the minimum and maximum sales amounts for all products, you would use the following SQL statements:
SELECT MIN(sales_amount) FROM sales; SELECT MAX(sales_amount) FROM sales;
These statements will return the minimum and maximum sales amounts for all products in the
Note that if the column specified in the
MAX() function contains null values, those values will be ignored in the calculation.