dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Apr 7, 2020

WEBINAR:

On-Demand

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


Understanding Least and Greatest 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  |
+------+ 
M S Sridhar
 
Thanks for your registration, follow us on our social networks to keep up-to-date