MAX function in MariaDB

MariaDB MAX To get the maximum value from a column in the table, the MariaDB MAX function is used.

Syntax:

SELECT expressions, 
MAX (aggregate_expression)  
FROM table_name  
WHERE conditions;

Parameters: Aggregate_expression: It is used to specify the column or expression to be utilised by the aggregate function.

Example 1: Using Group By Clause. Players Table:

ID	NAME	     SPORTS	   INCOME
1	Sachin	     Cricket	   5000000
2	Dhoni	     Cricket	   8000000
3	Sunil	     Football	   2000000
4	Srikanth     Badminton	   1000000
5	Mary	     Boxing	   3000000

Query:

SELECT sports, MAX(income) AS “Maximum Income”
FROM Players
GROUP BY sports;

Output:

SPORTS	        Maximum Income
Cricket 	8000000
Football	2000000
Badminton	1000000
Boxing  	3000000

Explanation: The ‘Players’ is an already existing table. Here we are retrieving the maximum value of the income of the players of the same SPORTS group, using the Group By clause with an aggregate function MAX.

Example 2: Players Table:

ID	NAME	      SPORTS	   INCOME
1	Sachin	      Cricket	   5000000
2	Dhoni	      Cricket	   8000000
3	Sunil	      Football	   2000000
4	Srikanth      Badminton	   1000000
5	Mary	      Boxing	   3000000

Query:

SELECT MAX(income) FROM Players;

Output:

8000000

Explanation: The maximum value of the INCOME is the result.

Please follow and like us:
Content Protection by DMCA.com