TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
 Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow

# Tip: Understanding Least and Greatest in MySQL

## Explore the least and greatest functions in MySQL.

 by Sridhar M S
 Apr 7, 2020

### WEBINAR:On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning

MySQL provides an inbuilt function called LEAST. This function takes arguments and returns the lowest value in the values provided.

Considering the values in the arguments to be 9, 11, 12, 15; we also know that the least among these is the value 9.

Now, the following SQL will return the SUM of the least number and 1. i.e. 9 + 1 = 10.

```SELECT LEAST (11, 15, 12, 9) + 1 AS SUM

+------+
| SUM  |
+------+
|  10  |
+------+```

Along similar lines, MySQL also provides an inbuilt function called GREATEST. This returns the greatest number among the arguments.

Considering the following, we have the greatest number as 15. i.e. 15 + 1 = 16.

```SELECT GREATEST (11, 15, 12, 9) + 1 AS SUM

+------+
| SUM  |
+------+
|  16  |
+------+ ```

Visit the DevX Tip Bank

Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.