# limit

relationalai.semantics.std.aggregates

```python
limit(limit: int, *args: AggValue | Ordering) -> Aggregate
```

Limit results based on ordering.

## Parameters

- `limit` (`int`) - Maximum number of results to return.
- `*args` (`AggValue` | `Ordering`, default: `()`) - Values or Ordering specifications to order by.

## Returns

- `Aggregate` - An `Aggregate` representing the computation of the limited results.

## Examples

Get top 5 employees by salary:

```python
select(Employee).where(aggregates.limit(5, aggregates.desc(Employee.salary)))
```

Get top 3 products by sales per category:

```python
select(Product).where(
    aggregates.limit(3, aggregates.desc(Product.sales))
    .per(Category)
    .where(Product.category == Category)
)
```

## Referenced By

1. [RelationalAI Documentation](/index.md)1) [Build With RelationalAI](/build/index.md)1. [Use advanced reasoning](/build/reasoning/index.md) / [Prescriptive reasoning](/build/reasoning/prescriptive/index.md) / [Solve a decision problem](/build/reasoning/prescriptive/decision-problems/index.md)1) [Add constraints](/build/reasoning/prescriptive/decision-problems/constraints/index.md)
   2) [What's new](/release-notes/index.md)1) [Python package and CLI release notes](/release-notes/python/index.md)1. [Python package and CLI 2.1.0](/release-notes/python/2.1.0/index.md)1) [Bug Fixes](/release-notes/python/2.1.0/index.md#bug-fixes)
