dcsimg
 

Submitted by: M S Sridhar(sridhar.ms@gmail.com)

Tuesday Apr 7th 2020 by M S Sridhar

Language: SQL, Expertise: Intermediate: Explore the least and greatest functions in MySQL.

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  |
+------+ 
Home
Mobile Site | Full Site