> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Returns an array with the first N items in ascending order.

# groupArraySorted

<h2 id="groupArraySorted">
  groupArraySorted
</h2>

Introduced in: v24.2.0

Returns an array with the first N items in ascending order.

**Syntax**

```sql theme={null}
groupArraySorted(N)(column)
```

**Parameters**

* `N` — The number of elements to return. [`UInt64`](/reference/data-types/int-uint)

**Arguments**

* `column` — Column for which to group into an array. [`Any`](/reference/data-types/index)

**Returned value**

Returns an array with the first N items in ascending order. [`Array`](/reference/data-types/array)

**Examples**

**Getting first 10 numbers**

```sql title=Query theme={null}
SELECT groupArraySorted(10)(number) FROM numbers(100);
```

```response title=Response theme={null}
┌─groupArraySorted(10)(number)─┐
│ [0,1,2,3,4,5,6,7,8,9]        │
└──────────────────────────────┘
```

**String sorting example**

```sql title=Query theme={null}
SELECT groupArraySorted(5)(str) FROM (SELECT toString(number) AS str FROM numbers(5));
```

```response title=Response theme={null}
┌─groupArraySorted(5)(str)─┐
│ ['0','1','2','3','4']    │
└──────────────────────────┘
```
