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_name
WHERE condition;
```

Explanation

  • The SELECT clause will select the specified column from the database table.

  • The MIN() function, with column_name as parameter, fetches the least value from the table. column_name is the name of the column to be worked on.

  • If any conditions are available, the where clause 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_data
WHERE id > 0

With this query, the smallest age value will be selected and displayed. The select query output should look like this:

bio_data view

Free Resources