MySQL MIN() and MAX() Functions

In MySQL, the MIN() and MAX() functions are used to retrieve the minimum and maximum values of a column in a table, respectively.

The syntax for using MIN() function is:

SELECT MIN(column_name) FROM table_name;

Here, column_name is the name of the column for which you want to find the minimum value, and table_name is the name of the table where the column exists.

For example, to find the minimum value of the price column in a table called products, you would use the following query:

SELECT MIN(price) FROM products;

Similarly, the syntax for using MAX() function is:

SELECT MAX(column_name) FROM table_name;

Here, column_name is the name of the column for which you want to find the maximum value.

For example, to find the maximum value of the price column in the products table, you would use the following query:

SELECT MAX(price) FROM products;

Both functions can also be used with the GROUP BY clause to find the minimum or maximum value for each group in a table.

For example, to find the minimum and maximum prices of products for each category, you could use the following query:

SELECT category, MIN(price), MAX(price)
FROM products
GROUP BY category;

This would return the name of each category, along with the minimum and maximum prices for products in that category.

Wordpress Social Share Plugin powered by Ultimatelysocial
Wordpress Social Share Plugin powered by Ultimatelysocial