2020-06-18 08:24:31 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/maxmap
2024-06-24 12:32:52 +00:00
sidebar_position: 165
2020-06-18 08:24:31 +00:00
---
2022-06-02 10:55:18 +00:00
# maxMap
2020-06-18 08:24:31 +00:00
2020-09-16 14:14:33 +00:00
Calculates the maximum from `value` array according to the keys specified in the `key` array.
2024-07-06 17:37:00 +00:00
**Syntax**
```sql
maxMap(key, value)
```
or
```sql
maxMap(Tuple(key, value))
```
Alias: `maxMappedArrays`
2020-09-16 14:14:33 +00:00
2024-07-06 17:37:00 +00:00
:::note
- Passing a tuple of keys and value arrays is identical to passing two arrays of keys and values.
- The number of elements in `key` and `value` must be the same for each row that is totaled.
:::
2020-09-16 14:14:33 +00:00
2024-07-06 17:37:00 +00:00
**Parameters**
2020-06-18 08:24:31 +00:00
2024-07-06 17:37:00 +00:00
- `key` — Array of keys. [Array ](../../data-types/array.md ).
- `value` — Array of values. [Array ](../../data-types/array.md ).
**Returned value**
- Returns a tuple of two arrays: keys in sorted order, and values calculated for the corresponding keys. [Tuple ](../../data-types/tuple.md )([Array](../../data-types/array.md), [Array ](../../data-types/array.md )).
**Example**
Query:
2020-06-18 08:24:31 +00:00
``` sql
SELECT maxMap(a, b)
2023-01-27 22:41:55 +00:00
FROM values('a Array(Char), b Array(Int64)', (['x', 'y'], [2, 2]), (['y', 'z'], [3, 1]))
2020-06-18 08:24:31 +00:00
```
2024-07-06 17:37:00 +00:00
Result:
2020-06-18 08:24:31 +00:00
``` text
2023-01-27 22:41:55 +00:00
┌─maxMap(a, b)───────────┐
│ [['x','y','z'],[2,3,1]]│
└────────────────────────┘
2020-06-18 08:24:31 +00:00
```