SQLite MIN function is used to fetch the minimum value of an expression.
Syntax:
SELECT MIN(aggregate_expression)
FROM tables
[WHERE conditions];
Syntax when you use Min function with GROUP BY clause:
SELECT expression1, expression2, ... expression_n
MIN(aggregate_expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n;
Example1:
We have a table named “STUDENT”, having the following data:

Retrieve the lowest fees of the student from the “STUDENT” table:
SELECT MIN(FEES) AS "Lowest Fees"
FROM STUDENT;
Output:

Example2:
Using GROUP BY clause with MIN function:
Retrieve NAME and MIN FEES from the table “STUDENT” and ORDER BY the data by NAME:
SELECT NAME, MIN(FEES) AS "Lowest Fees"
FROM STUDENT
WHERE ID <= 5
GROUP BY NAME;
Output:

Leave a Reply