# MV_SORT

The MV_SORT function sorts the values in a multivalued field in lexicographical order.

## Syntax

`MV_SORT(field, order)`

### Parameters

#### field

Multivalue expression to be sorted. If the value is `null`, the function returns `null`.

#### order

Optional. Specifies the sort order. Valid options are `ASC` (ascending) and `DESC` (descending). The default is `ASC`.

## Examples

Sorts the values in the array `[4, 2, -3, 2]` in both ascending and descending order, assigning the sorted arrays to `sa` and `sd` respectively.

```esql
ROW a = [4, 2, -3, 2]
| EVAL sa = mv_sort(a), sd = mv_sort(a, "DESC")
```
This example sorts the array `[4, 2, -3, 2]` in ascending order and descending order, storing the results in `sa` and `sd` respectively.
