# max (/docs/reference/sql/aggregate-functions/max)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

Aggregate function that calculates the maximum across a group of values.

**Syntax**

```sql
max(column)
```

**Arguments**

* `column` — Column name or expression. [`Any`](/reference/data-types)

**Returned value**

The maximum value across the group with type equal to that of the input. [`Any`](/reference/data-types)

**Examples**

**Simple max example**

```sql title=Query
CREATE TABLE employees (name String, salary UInt32) ENGINE = Memory;
INSERT INTO employees VALUES ('Alice', 3000), ('Bob', 4000), ('Charlie', 3500);

SELECT max(salary) FROM employees;
```

```text title=Response
┌─max(salary)─┐
│        4000 │
└─────────────┘
```

**Max with GROUP BY**

```sql title=Query
CREATE TABLE sales (department String, revenue UInt32) ENGINE = Memory;
INSERT INTO sales VALUES ('Engineering', 100000), ('Engineering', 120000), ('Marketing', 80000), ('Marketing', 90000);

SELECT department, max(revenue) FROM sales GROUP BY department ORDER BY department;
```

```text title=Response
┌─department──┬─max(revenue)─┐
│ Engineering │       120000 │
│ Marketing   │        90000 │
└─────────────┴──────────────┘
```

**Note about non-aggregate maximum**

```sql title=Query
-- If you need non-aggregate function to choose a maximum of two values, see greatest():
SELECT greatest(a, b) FROM table;
```

*Introduced in version 1.1.0.*
