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


advertisement
 

Tip: Understanding Least and Greatest in MySQL

Explore the least and greatest functions in MySQL.


advertisement

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.
Thanks for your registration, follow us on our social networks to keep up-to-date