---
metadata:
  - name: generator
    content: Diplodoc Platform v5.51.0
alternate:
  - https://e2e.viewer-test.ydocs.io/en/yql/syntax/select/order_by.md
  - https://e2e.viewer-test.ydocs.io/ru/yql/syntax/select/order_by.md
  - href: https://e2e.viewer-test.ydocs.io/en/yql/syntax/select/order_by.md
    type: text/markdown
    title: Markdown version
  - href: https://e2e.viewer-test.ydocs.io/en/llms.txt?revision=ytsaurus-test-revision5
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://e2e.viewer-test.ydocs.io/en/llms.txt?revision=ytsaurus-test-revision5

# ORDER BY

Sorting the `SELECT` result using a comma-separated list of sorting criteria. As a criteria, you can use a column value or an expression on columns. Ordering by column sequence number is not supported (`ORDER BY N` where `N` is a number).

Each criteria can be followed by the sorting direction:

- `ASC`: Sorting in the ascending order. Applied by default.
- `DESC`: Sorting in the descending order.

Multiple sorting criteria will be applied left-to-right.

## Example

```yql
SELECT key, string_column
FROM my_table
ORDER BY key DESC, LENGTH(string_column) ASC;
```

You can also use `ORDER BY` for [window functions](https://e2e.viewer-test.ydocs.io/en/yql/syntax/window.md).
