---
title: "Explain the purpose of the MAX() and MIN() functions in SQL and provide examples."  
description: "Explain the purpose of the MAX() and MIN() functions in SQL and provide examples."  
author: "Revati S Misra"  
published: 2023-06-30  
updated: 2023-07-01  
canonical: https://www.mindstick.com/forum/158913/explain-the-purpose-of-the-max-and-min-functions-in-sql-and-provide-examples  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# Explain the purpose of the MAX() and MIN() functions in SQL and provide examples.

[Explain the purpose](https://www.mindstick.com/forum/159480/explain-the-purpose-of-the-virtual-keyword-and-virtual-functions-in-c-plus-plus) of the [MAX](https://www.mindstick.com/articles/1155/count-max-min-function-in-excel)() and MIN() [functions in SQL](https://www.mindstick.com/forum/33707/what-is-the-difference-between-rank-and-dense_rank-functions-in-sql-server) and provide examples.

## Replies

### Reply by Aryan Kumar

Sure. The MAX() and MIN() [functions](https://www.mindstick.com/forum/160140/explain-the-role-of-functions-as-a-service-faas-in-serverless-computing) in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) are aggregate functions that are used to return the maximum and minimum values of a column, respectively. The syntax for the MAX() and MIN() functions is:

SQL

```plaintext
MAX(column_name)
MIN(column_name)
```

- `column_name` is the name of the column that you want to return the maximum or minimum value of.

The MAX() and MIN() functions can be used in a variety of ways, such as:

- To find the maximum or minimum value of a column in a table.
- To filter results based on the maximum or minimum value of a column.
- To compare the maximum or minimum value of a column to other values.

For example, the following query will return the maximum price of all products in the `products` table:

SQL

```plaintext
SELECT MAX(price)
FROM products;
```

The following query will return all products in the `products` table where the price is less than the maximum price:

SQL

```plaintext
SELECT *
FROM products
WHERE price < MAX(price);
```

The following query will return the minimum age of all customers in the `customers` table:

SQL

```plaintext
SELECT MIN(age)
FROM customers;
```

The following query will return all customers in the `customers` table where the age is greater than the minimum age:

SQL

```plaintext
SELECT *
FROM customers
WHERE age > MIN(age);
```

The MAX() and MIN() functions are powerful tools that can be used to perform a variety of tasks with your SQL data.


---

Original Source: https://www.mindstick.com/forum/158913/explain-the-purpose-of-the-max-and-min-functions-in-sql-and-provide-examples

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
