---
title: "Max Aggregate Function"
description: "Group function to find the maximum value from a group of numerical values or text values."
language: en
source_language: en
translation_state: complete
canonical: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/aggregate-functions/max-aggregate-function
original: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/aggregate-functions/max-aggregate-function
updated: 2026-10-25T00:00:00Z
license: https://documentation.invantive.eu/en/
---

## Syntax
```mermaid
%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    maxAggregateFunction_start((START))
    maxAggregateFunction_start --> maxAggregateFunction_0_0[MAX]:::quoted
    maxAggregateFunction_0_0 --> maxAggregateFunction_0_1["("]:::quoted
    maxAggregateFunction_0_1 --> maxAggregateFunction_0_2[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>]
    maxAggregateFunction_0_1 --> maxAggregateFunction_0_1a[DISTINCT]:::quoted
    maxAggregateFunction_0_1 --> maxAggregateFunction_0_1b[ALL]:::quoted
    maxAggregateFunction_0_1a --> maxAggregateFunction_0_2
    maxAggregateFunction_0_1b --> maxAggregateFunction_0_2
    maxAggregateFunction_0_2 --> maxAggregateFunction_0_3[")"]:::quoted
    maxAggregateFunction_0_3 --> maxAggregateFunction_end((END))
```

## Purpose
Group function to find the maximum value from a group of numerical values or text values. Occurrences of `null` are ignored; when solely `null` values are present, the outcome is `null`. Texts are compared by the code of each character (ordinal), as in `order by`, so the maximum of `'a'` and `'B'` is `'a'`. Up to release 27.0 texts were compared by the language settings of the computer. To find the largest of several values within one row, use [[GREATEST]]. `DISTINCT` and `ALL` are accepted from release 28.0 and do not change the outcome.

## Examples
The following example retrieves the highest credit limit across a customer base of five customers:
```sql
select max(cus.credit_limit)
from   csvtable
       ( passing 'Acme Industries#Manufacturing#12500#50000|Bergmann GmbH#Manufacturing#0#25000|Carlson Ltd#Wholesale#2500#10000|Dubois SA#Wholesale#7500#10000|Everest BV#Services##5000'
         row delimiter '|'
         column delimiter '#'
         columns name         varchar2 position next
         ,       segment      varchar2 position next
         ,       balance      number   position next
         ,       credit_limit number   position next
       ) cus

-------------------
50000
```
The following example retrieves the highest outstanding balance per customer segment; the balance of the sole Services customer is `null`, so the outcome for that segment is empty:
```sql
select cus.segment
,      max(cus.balance)
from   csvtable
       ( passing 'Acme Industries#Manufacturing#12500#50000|Bergmann GmbH#Manufacturing#0#25000|Carlson Ltd#Wholesale#2500#10000|Dubois SA#Wholesale#7500#10000|Everest BV#Services##5000'
         row delimiter '|'
         column delimiter '#'
         columns name         varchar2 position next
         ,       segment      varchar2 position next
         ,       balance      number   position next
         ,       credit_limit number   position next
       ) cus
group
by     cus.segment
order
by     cus.segment

-------------------
Manufacturing    12500
Services
Wholesale        7500
```