What is the SQL MIN() function?
Overview
The SQL MIN() is a computational command in the structured query language. It performs computations on table columns.
It will return the least value from the selected column.
Syntax
```SELECT MIN(column_name)FROM table_nameWHERE condition;```
Explanation
-
The
SELECTclause will select the specified column from the database table. -
The
MIN()function, withcolumn_nameas parameter, fetches the least value from the table.column_nameis the name of the column to be worked on. -
If any conditions are available, the
whereclause provides you with the avenue to use it.
Example
We create an employee biodata table, bio_data.
bio_data
id | idCardNo | fname | lname | age |
1 | 2019rt500 | James | Micheal | 16 |
2 | 2020rt089 | Jonah | Tyron | 38 |
3 | 2000rt410 | Juan | Obodo | 18 |
4 | 2019rt0210 | Ella | Fella | 90 |
This table can be queried with the following SQL statement:
SELECT MIN(age)FROM bio_dataWHERE id > 0
With this query, the smallest age value will be selected and displayed. The select query output should look like this: