LIMIT clause

Updated at:
Copy as MD

Simple Log Service returns 100 rows by default. Use the LIMIT clause to specify a different number of rows to return.

Syntax

The LIMIT clause supports two formats.

  • Return the first x rows.

    LIMIT x
  • Return x rows starting from offset y.

    LIMIT y, x
Important
  • The LIMIT clause applies only to final results, not intermediate results within a SQL query.

  • The LIMIT y,x clause is not supported inside a subquery. For example, the following statement is invalid: * | select count(1) from ( select distinct(url) from limit 0,1000).

Parameters

Parameter

Description

x

The number of rows to return.

  • For LIMIT x, the valid range for x is [0, 1,000,000].

  • For LIMIT y, x, the valid range for x is [0, 10,000].

y

The number of rows to skip. Valid range: [0, 1,000,000].

Important

The sum of x and y cannot exceed 1,000,000.

Examples

  • Return the first 200 rows from the result set.

    • Query statement

      * | SELECT  request_time LIMIT 200
    • Result: Returns 200 values from the request_time field, such as 60.0, 63.0, and 73.0.

  • Return 1,000 rows with an offset of 100.

    • Query statement

      * | SELECT  request_time LIMIT 100,1000
    • Result: Returns 1,000 values from the request_time field, with an offset of 100.

  • Return the top three request URIs with the longest request times.

    • Query statement

      * |
      SELECT
        request_uri AS top_3,
        request_time
      ORDER BY
        request_time DESC
      LIMIT
        3
    • Result: Returns the three URIs with the longest request times: /request/path-3/file-2 (80.0), /request/path-2/file-4 (80.0), and /request/path-0/file-8 (79.0).