MIN()
MIN(expression)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. Here is an example:
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 earlier in this chapter for
additional ways to use
MIN().