MySQL Tutorial
The MIN() function returns the smallest value of the selected column.
SELECT MIN(column_name)
FROM table_name
WHERE condition;
Let's put these statements into real use.
We've a table named Students in our database that contains the following records:
ROLL_NO | NAME | SUBJECT |
---|---|---|
1 | Will | JAVA |
2 | SAM | Python |
3 | Sara | HTML | 4 | Rim | Java |
5 | Micheal | SQL |
6 | Lara | JAVA |
Now lets select the smallest value of ROLL_NO from Students Table.
SELECT MIN(ROLL_NO) AS "SmallestRollNo"
FROM Students;
The above SELECT statement returns the smallest value.
SmallestRollNo |
---|
1 |
We can select the smallest value from table with where condition.
SELECT MIN(ROLL_NO) AS "SmallestRollNo"
FROM Students
WHERE SUBJECT='HTML'
The above SELECT statement retrieve the smallest value if the SUBJECT is HTML.
SmallestRollNo |
---|
3 |