# ORDER BY and LIMIT

> Sort the rows by metrics or fields, keep the first ones, and page through the rest.

`ORDER BY` sorts the rows; `LIMIT` keeps the first ones, and `OFFSET` skips some before that.

```sql
FROM deals
SHOW won_value
GROUP BY owner
ORDER BY won_value DESC
LIMIT 5
```

## ORDER BY

```sql
ORDER BY <metric | field | alias> [ASC | DESC][, ...]
```

Sort by anything you `SHOW` or `GROUP BY`, by an `AS` name, or by a function you show (`ORDER BY sum(amount) DESC`). `ASC` is the default. Later columns break ties:

```sql
ORDER BY stage ASC, value DESC
```

## LIMIT and OFFSET

```sql
LIMIT <n> [OFFSET <n>]
```

`LIMIT 10 OFFSET 10` shows rows 11 to 20. A report returns at most 1,000 rows.

In a [cohort report](https://workstation.repzo.com/docs/analytics/repzoql/cohort), `LIMIT` sets how many periods each cohort follows.

## Top N

For "top 5 owners", either sort and limit, or use [TOP](https://workstation.repzo.com/docs/analytics/repzoql/group-by#top) to keep the rest as an **Other** row:

```sql
GROUP BY TOP 5 owner
```

## Related pages

- [GROUP BY](https://workstation.repzo.com/docs/analytics/repzoql/group-by)
- [VISUALIZE](https://workstation.repzo.com/docs/analytics/repzoql/visualize)
