Skip to content

limit

relationalai.semantics.std.aggregates
limit(limit: int, *args: AggValue | Ordering) -> Aggregate

Limit results based on ordering.

  • limit

    (int) - Maximum number of results to return.
  • *args

    (AggValue | Ordering, default: ()) - Values or Ordering specifications to order by.
  • Aggregate - An Aggregate representing the computation of the limited results.

Get top 5 employees by salary:

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

Get top 3 products by sales per category:

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