The Code Developer

MySQL MIN Function

Introduction to MySQL MIN Function

This MySQL tutorial explains how to use the MIN function with syntax and examples. The MySQL MIN function returns the minimum value in a set of values.

MIN() Syntax

SELECT MIN(column_name)
FROM table_name
WHERE condition;

To understand MIN function, consider an “books” table, which is having the following records:

SELECT * FROM books;
BookIdBookNamePriceAuthor
1Learning PHP, MySQL, and JavaScript17Robin Nixon
2Ubuntu: Up and Running23Robin Nixon
3PHP and MySQL Web Development12Luke Welling
4Murach's PHP and MySQL14Joel Murach
5Murach's Java Programming62Joel Murach
6Head first php mysql22Lynn Beighley
7Head first sql11Lynn Beighley
8HTML5 for IOS and Android: A Beginner's Guide4Robin Nixon

The following MySQL statement finds the price of the most cheapest book:

SELECT MIN(Price) AS SmallestPrice
FROM books;
SmallestPrice
4

The following MySQL statement finds the price of the most cheapest book in each author, sorted low to high:

SELECT MIN(Price) AS SmallestPrice, Author
FROM books
GROUP BY Author
ORDER BY SmallestPrice ASC;
SmallestPriceAuthor
4Robin Nixon
11Lynn Beighley
12Luke Welling
14Joel Murach