Search

Get Started: SQL MIN() and MAX() Functions

##### In This Article, You Will Know About SQL MIN() MAX() Functions.

SQL MIN() MAX() Functions – Before moving ahead, let’s know a bit about SQL Top Clause.

### SQL MIN() Function

The SQL MIN function returns the lowest value from the selected column.

Syntax

```				```
SELECT MIN(column_name)
FROM table_name
WHERE condition;
```
```

### SQL MAX() Function

The SQL MAX function returns the largest value from the selected column.

Syntax

```				```
SELECT MAX(column_name)
FROM table_name
WHERE condition;
```
```

### Example Database

Below is the example of a database table named “details.”

 Id Name Class section_id 1 Alex 5 1 2 Rolex 6 2 3 Salex 7 2 4 Lelex 8 3 5 Kelex 9 5

### MIN() Example

Example: Use MIN() function to return the smallest record from the selected column.

```				```
SELECT MIN(Class)
FROM details;
```
```

As a result, it returns the smallest number from the selected column.

Example: Use MIN() function to return the smallest record from the selected column.

```				```
SELECT MIN(Class)
FROM details
WHERE section_id = 1;
```
```

As a result, it returns the smallest number from the selected column.

Note: Here we defined the condition where to check for smallest number in the column.

### MAX() Example

Example: Use MAX() function to return the largest record from the selected column.

```				```
SELECT MAX(Class)
FROM details;
```
```

As a result, it returns the largest number from the selected column.

Example: Use MAX() function to return the largest record from the selected column.

```				```
SELECT MAX(Class)
FROM details
WHERE section_id = 5;
```
```

As a result, it returns the largest number from the selected column.

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

Share on