# Sort a Table

### Overview

This procedure sorts a table by one or more columns. The sort order (ascending or descending) can be specified. Optionally, you can specify a list of sort orders for multiple columns.

This is useful in a variety of situations—for example, you can sorting a score or sales column, arrange items alphabetically by name or category, or sort by date to show the most recent entries first.

### Input Concepts

| Concept  | Type  | Description                                                                                                     | Default    | Required |
| -------- | ----- | --------------------------------------------------------------------------------------------------------------- | ---------- | -------- |
| `table`  | table | The table to be sorted.                                                                                         | No default | Yes      |
| `column` | text  | The column(s) by which the table should be sorted. Can be a single column name or comma-separated list.         | No default | Yes      |
| `order`  | text  | Optional sort order for single column. Format: ascending / descending column\_name                              | No default | No       |
| `orders` | text  | Optional list of sort orders for multiple columns. Format: ascending / descending column\_name for each column. | No default | No       |

### Output Concepts

| Concept | Description       |
| ------- | ----------------- |
| `table` | The sorted table. |

### Examples

For these examples, say we create a table using the following command:

```
create a table where
    the column names are "name", "age" and "address"
```

#### 1. Sort with Default Ascending Order

In this example, no order is specified, so the default sorting order is ascending.

```
sort the table by "age"
```

#### 2. Sort with Default Descending Order

In this example, the "age" column is sorted in descending order.

```
sort the table by "age" where
    the order is "descending age"
```

#### 3. Sort Multiple Columns

In this example, both the "city" and "age" columns are sorted in different orders.

```
sort the table by "city, age" where
    the orders are "descending city", "ascending age"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kognitos.com/legacy/legacy-experience/automation-areas/tables-v2/query-a-table/sort-a-table.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
