MIN( )

This MySQL function returns the lowest number in the values for a given column.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

MIN(expression)

Explanation

This function returns the lowest number in the values for a given column. It's normally used in conjunction with a GROUP BY clause specifying a unique column, so that values are compared for each unique item separately.

.

Examples

SELECT CONCAT(name_first, SPACE(1), name_last) AS rep_name, 
MIN(sale_amount) AS smallest_sale,
MAX(sale_amount) AS biggest_sale
FROM sales
JOIN sales_reps USING(sales_rep_id)
GROUP BY sales_rep_id;

In this example, we retrieve the smallest sale and largest sale made by each sales representative. We use JOIN to join the two tables to get the sales rep's name. Because MAX( ) is very similar, see the examples in its description for additional ways to use MIN( ).