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;
BookIdBookNamePriceAuthorpublishedDate
1Learning PHP, MySQL, and JavaScript17Robin Nixon2017-02-02
2Ubuntu: Up and Running23Robin Nixon2017-03-23
3PHP and MySQL Web Development12Luke Welling2017-06-14
4Murach's PHP and MySQL14Joel Murach2017-06-17
5Murach's Java Programming62Joel Murach2017-07-28
6Head first php mysql22Lynn Beighley2017-07-31
7Head first sql11Lynn Beighley2017-09-10
8HTML5 for IOS and Android: A Beginner's Guide4Robin Nixon2017-09-12

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

Leave A Reply

Your email address will not be published.