2020-06-18 08:24:31 +00:00
|
|
|
---
|
2022-08-28 14:53:34 +00:00
|
|
|
slug: /en/sql-reference/aggregate-functions/reference/max
|
2024-06-24 12:32:52 +00:00
|
|
|
sidebar_position: 162
|
2022-08-28 21:34:50 +00:00
|
|
|
title: max
|
2020-06-18 08:24:31 +00:00
|
|
|
---
|
|
|
|
|
2021-04-28 01:37:44 +00:00
|
|
|
Aggregate function that calculates the maximum across a group of values.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```
|
|
|
|
SELECT max(salary) FROM employees;
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
SELECT department, max(salary) FROM employees GROUP BY department;
|
|
|
|
```
|
|
|
|
|
|
|
|
If you need non-aggregate function to choose a maximum of two values, see `greatest`:
|
|
|
|
|
|
|
|
```
|
|
|
|
SELECT greatest(a, b) FROM table;
|
|
|
|
```
|