MySQL LEAST Function: Complete Guide

In MySQL, the LEAST function is used to return the minimum value from a set of values. It takes multiple parameters, compares them, and returns the smallest value. For example, you can use the LEAST function to compare values from two columns and return the minimum value, or compare multiple constant values and return the minimum value.

The basic syntax of the LEAST function is as follows:

LEAST(value1, value2, value3, ...)

Among them, value1, value2, value3, … are the values to be compared.

For example, suppose there is a table called “products” which contains columns product_id, product_name, and price. To retrieve the lowest price from the price column, you can use the following query:

SELECT LEAST(price) AS min_price FROM products;

This query will return the lowest price in the price column as min_price. The LEAST function can be used in conjunction with other functions and conditions for data analysis and filtering based on specific needs.

bannerAds