Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Max(), Min() and Mod() Function in MariaDB

  • Last Updated : 13 Oct, 2020

1. Max() Function :
In MariaDB, the Max() function is used to returns the maximum value of an expression. In this function, a query is passed and in the eligible records which value will be maximum, that will return a result. It works like maximum function in the processed query. An expression will be passed as a parameter and it will return the maximum value in the expression.

Syntax :

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

Max(expression)

Parameter : Required. An expression.
expression : The input value.
Returns : The maximum value in the expression.

Table – IPL



Team_idTeamnameScore
1RR140
2CSK210
3MI160
4DC170

Example-1 :

SELECT Max(Score) AS MAX_Score
FROM IPL;

Output :

MAX_Score
210



Example-2 :

SELECT Max(Score) AS MAX_Score
FROM IPL
WHERE Score < 190;

Output :

MAX_Score
170



Example-3 :

SELECT Max(Score) AS MAX_Score
FROM IPL
WHERE Score < 160;

Output :

MAX_Score
140


2. Min() Function :
In MariaDB, the Min() function is used to returns the minimum value of an expression. In this function, a query is passed and in the eligible records which value will be minimum, that will return a result. It works like minimum function in the processed query. An expression will be passed as a parameter and it will return the minimum value in the expression.



Syntax :

Min(expression)

Parameter : Required. An expression.
expression : The input value.
Returns : The minimum value in the expression.

Example-1 :

SELECT Min(Score) AS Min_Score
FROM IPL;

Output :

Min_Score
140



Example-2 :

SELECT Min(Score) AS Min_Score
FROM IPL
WHERE Score > 150;

Output :

Min_Score
160



Example-3 :

SELECT Min(Score) AS Min_Score
FROM IPL
WHERE Score > 170; 

Output :

Min_Score
210


3. Mod() Function :
In MariaDB, the Mod() function used to return the remainder of n divided by m.In this function, two-parameter will be passed first is n (a value that will be divided by m) and the second will be m (a value that will be divided into n). The function uses the formula of n / m and returned what will be a remainder without any rounding.



Syntax :

MOD(n, m)
OR
n MOD m
OR
n % m 

Parameters : Required. Two numeral values.

  • n : Divident (Value that will be divided).
  • m : Divisor (Value which the dividend is being divided by).

Returns : Remainder value (without any rounding) as the result of the division.

Example-1 :

SELECT MOD(20, 5);

Output :

0



Example-2 :

SELECT 21 MOD 4;

Output :

1



Example-3 :

SELECT 51 % 7;

Output :

2
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!