100 Days of SQL

sql

Day 11 – SQL MIN() and MAX() Functions

In SQL, the MIN() and 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 MIN() and MAX() functions is as follows:


SELECT MIN(column_name) FROM table_name;
SELECT MAX(column_name) FROM table_name;

Here, 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 product_name and 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 sales table.

Note that if the column specified in the MIN() or MAX() function contains null values, those values will be ignored in the calculation.