CodesJava

Easy learning with example program codes

MIN function in MariaDB

MariaDB MIN
To get the minimum value from a column in the table, the MariaDB MIN function is used.

Syntax:

SELECT expressions, 
MIN (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, MIN(income) AS “Minimum Income”
FROM Players
GROUP BY sports;

Output:

SPORTS	        Minimum Income
Cricket	        5000000
Football	2000000
Badminton	1000000
Boxing	        3000000

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

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 MIN(income) FROM Players;

Output:

1000000

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

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status