Skip to main content

LIMIT

Restrict the number of rows returned.

Syntax

LIMIT expression

Parameters

  • expression - Non-negative integer specifying the maximum number of rows to return

Description

The LIMIT command restricts the output to a specified maximum number of rows. The expression must evaluate to a non-negative integer value. When the dataset contains fewer rows than the limit, all rows are returned.

You typically use LIMIT in combination with SORT to retrieve the top or bottom N results from an ordered dataset. When you use it without sorting, LIMIT returns an arbitrary subset of rows, which may vary between query executions.

The limit is applied after all other operations in the pipeline, making it useful for controlling output size while preserving the full computation context for earlier commands.

  • SORT - Order rows by expressions (commonly used with LIMIT)