# sort Parameter

> Order the rows of an answer with the sort parameter of API Maker - one or several columns, ascending or descending with a minus sign, as a string or as an object.

Source: https://docs.apimaker.dev/v1/docs/apis-all/query-params/sort.html

`sort` orders the rows. Name the columns, with `-` in front of a column for descending order.

**Ascending**

```text
GET /api/schema/admin/mysql8/inventory/customers?sort=customer_id
```

**Descending**

```text
GET /api/schema/admin/mysql8/inventory/customers?sort=-customer_id
```

**Several columns : by last update, newest first, then by first name**

```text
GET /api/schema/admin/mysql8/inventory/customers?sort=-last_update,first_name
```

**Body of the query APIs : a string or an object**

```json
{ "find": {}, "sort": "-last_update,first_name" }
{ "find": {}, "sort": { "last_update": -1, "first_name": 1 } }
```

**Answer of ?sort=-customer_id**

```json
{
    "success": true,
    "statusCode": 200,
    "data": [
        { "customer_id": 5, "first_name": "Eve", "last_name": "Page" },
        { "customer_id": 4, "first_name": "Eve", "last_name": "Mathly" },
        { "customer_id": 3, "first_name": "Mallory", "last_name": "Brown" }
    ]
}
```

- Spaces around the commas are fine : `-last_update, first_name`.
- On MongoDB a nested field sorts too : `sort=address.city`.
- Inside a `deep` item, `sort` orders the related rows of each parent.
- Sorting a big table on a column without an index is slow ; [Index Maker](https://docs.apimaker.dev/v1/extensions/index_maker/introduction.html) finds the queries which need one.

- [select →](https://docs.apimaker.dev/v1/docs/apis-all/query-params/select.html)
- [limit](https://docs.apimaker.dev/v1/docs/apis-all/query-params/limit.html)
