MariaDB is a relational database language that is similar to SQL. We know that in a relational database language, the data is stored in the form of relations which are nothing but the tables. Similar to SQL which has aggregate functions such as MIN(), MAX(), AVG(), and LEAST() functions. These aggregate functions in the MariaDB help us to make operations faster and easier. MariaDB is a cost-effective solution for small and large web projects compared to other databases.
In this article, We will learn about the MIN Function in MariaDB along with its syntax, practical examples of some functions, and so on.
MIN Function in MariaDB
MIN Function in MariaDB is a function that is used to return the smallest or minimum value of columns. With the help of the MIN, the Function user can easily get the minimum value of the table or database. Let's understand some examples for better understanding.
Note: We can perform the MIN, and MAX operations with the numerical data as well as the Strings.
Examples of MariaDB MIN Functions
For a better understanding of Min Function in MariaDB, we need a table on which we will perform various operations and queries. So in this article, we have a DETAILS table which consists of id, NAME, and SUBJECT as Columns. If you don't know How to Create a Table in SQLite then refer to this. After inserting data into the DETAILS Table. The table looks:
Output:
Deails TableExplanation: In the above image we have retreived all the records from the table DETAILS.
Example 1: Using the MIN( ) Function to Get Minimum Value
In this example, We are going to use the MIN() function with the table DETAILS. Generally as mentioned earlier the aggregate operators are used to make the operation easier.
Generally the MIN() function is used to return the minimum value from the given column in the relation. When we use the MIN() function it checks for the lexographical order and returns the string based on that.
Query:
SELECT MIN(NAME) FROM DETAILS;
Output:
OutputExplanation:
- In the above image we have used the MIN() function along with the string fields.
- The MIN() Function when used along with the Min .It returns the smallest string in the lexographical order.
- As Durga is smallest in the lexographic order across all name as it returns Durga.
Example 2 :Using MIN() Function With the Numeric Fields
Let's find the minimum id in the DETAILS Table.
Query:
SELECT MIN(id) FROM DETAILS;
Output:
OutputExplanation:
- In the above image we have used the MIN() function along with the numeric fields.
- Here id is having the numerical values.
- So when we use the MIN() function along with the id. It returns 1 as 1 is the smallest value.
Example 3: Using the MIN() Function with GROUPBY Clause
In this query we are going to use GROUP BY Clause . The GROUP BY Clause is used to group a particular field with the help of aggregate functions. In this query we will use the aggregate functions such as LENGTH and COUNT .
- COUNT : The COUNT() function is used return the number of fields that have particular value in the relation.
- LENGTH : The LENGTH() is used to return the length of a string type .The Length is mainly used with the string fields .
In the below query we are going to extract the Minimum name in number of names grouped by their length. Generally when they are grouped by the length they give the name on the basis of the lexographic order.
Query:
SELECT MIN(name) , LENGTH(NAME) AS NAME_LENGTH FROM students GROUP BY LENGTH(NAME) ;
Output:
MIN WITH GROUP BY OUTPUTExplanation: In the above Query, We have fetched the name of person based on the length of name (string). The output names are sorted according to their names length.
Example 4: Using the MIN Function Along With the HAVING Clause
In this query we are going to use HAVING Clause along with the MIN function. Generally we use the HAVING Clause along with the aggregate operators. In the below query we are going to extract the name which is of lowest lexographical order from the records whose length is of exactly 5. We have grouped the records with the name.
Query:
SELECT MIN(name) , LENGTH(name) FROM students GROUP BY name HAVING LENGTH(name)=5;
Output:
MIN HAVING OUTPUTExplanation: In the above Query, We have fetched name of person and the length of name string. Here we have grouped the name of DETAILS and find the name along with length of name(string) is 5.
CONCLUSION
Aftere reading the whole article now we have good understanding of MIN Function in MariaDB. MariaDB is used to find the minimum/smallest value according to the conditions of queries. Finally aggregate operators are used to derive the descriptive statistics. The aggregations are used to compute the mathematical calculations. For example the data of population and censux are very large.The manual caluculation for this takes a large ammount of time . In order to make the caluculations easier we use the aggregate operations.
Similar Reads
SQL Interview Questions
Are you preparing for a SQL interview? SQL is a standard database language used for accessing and manipulating data in databases. It stands for Structured Query Language and was developed by IBM in the 1970s, SQL allows us to create, read, update, and delete data with simple yet effective commands.
15+ min read
SQL Tutorial
SQL is a Structured query language used to access and manipulate data in databases. SQL stands for Structured Query Language. We can create, update, delete, and retrieve data in databases like MySQL, Oracle, PostgreSQL, etc. Overall, SQL is a query language that communicates with databases.In this S
11 min read
Non-linear Components
In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
SQL Commands | DDL, DQL, DML, DCL and TCL Commands
SQL commands are crucial for managing databases effectively. These commands are divided into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language (TCL). In this article, we will e
7 min read
SQL Joins (Inner, Left, Right and Full Join)
SQL joins are fundamental tools for combining data from multiple tables in relational databases. Joins allow efficient data retrieval, which is essential for generating meaningful observations and solving complex business queries. Understanding SQL join types, such as INNER JOIN, LEFT JOIN, RIGHT JO
6 min read
Normal Forms in DBMS
In the world of database management, Normal Forms are important for ensuring that data is structured logically, reducing redundancy, and maintaining data integrity. When working with databases, especially relational databases, it is critical to follow normalization techniques that help to eliminate
8 min read
Class Diagram | Unified Modeling Language (UML)
A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
ACID Properties in DBMS
In the world of Database Management Systems (DBMS), transactions are fundamental operations that allow us to modify and retrieve data. However, to ensure the integrity of a database, it is important that these transactions are executed in a way that maintains consistency, correctness, and reliabilit
8 min read
Spring Boot Tutorial
Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Backpropagation in Neural Network
Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read