SQL SELECT MIN
The MIN is an aggregate function in SQL which returns the smallest value from the multiple values of the column in the table.
Syntax of SQL Min() Function
In this syntax, we can also use the MIN function with the WHERE clause for selecting the minimum value from the filtered records.
Two Examples of SQL Min Function
Example 1: This example describes how to use the MIN function in SQL.
Let's create a simple table on which the MIN function is to be run.
The following CREATE TABLE statement creates the Bikes_Details table with five fields:
The following INSERT query inserts the record of cars into the Bikes_Details table:
The following SELECT query shows the data of the Bikes_Details table:
The following query shows the smallest value from the Bike_Number column of the above Bikes_Details table:
Example 2: This example describes you how to use the MIN function with the WHERE clause.
The following query creates the College_Student_Details table using the CREATE TABLE statement:
The following SQL queries insert the record of students into the above table using INSERT INTO statement:
Let's see the record of the above table using the following SELECT statement:
The following MIN query displays the lowest marks above 70 from the Student_Marks column of the College_Student_Details table:
MIN Function with SQL GROUP BY clause
The MIN Function with GROUP BY clause shows the smallest value in each group from the table.
The syntax to use Group BY Clause with MIN Function is given below:
Example of MIN Function with GROUP BY Clause
Let's take the above College_Student_Details table to understand the concept of MIN function With GROUP BY Clause.
The following query shows the minimum marks of student in each course from the above College_Student_Details table: