Skip to main content

groupArrayLast

Introduced in: v23.1.0 Creates an array of the last argument values. For example, groupArrayLast(1)(x) is equivalent to [anyLast(x)]. In some cases, you can still rely on the order of execution. This applies to cases when SELECT comes from a subquery that uses ORDER BY if the subquery result is small enough. Syntax
groupArrayLast(max_size)(x)
Parameters
  • max_size — Maximum size of the resulting array. UInt64
Arguments
  • max_size — Maximum size of the resulting array. UInt64
  • x — Argument (column name or expression). Any
Returned value Returns an array of the last argument values. Array(T) Examples Usage example
Query
SELECT groupArrayLast(2)(number+1) numbers FROM numbers(10);
Response
┌─numbers─┐
│ [9,10]  │
└─────────┘
Comparison with groupArray
Query
-- Compare with groupArray (first values)
SELECT groupArray(2)(number+1) numbers FROM numbers(10);
Response
┌─numbers─┐
│ [1,2]   │
└─────────┘
Last modified on June 8, 2026