You need to enable JavaScript to run this app.
Torch Log Service

Torch Log Service

Copy page
Download PDF
SQL syntax
LIMIT syntax
Copy page
Download PDF
LIMIT syntax
The LIMIT syntax is used to limit the number of result rows returned by a SELECT statement. By default, only 100 rows of data are returned when performing query and analysis on logs. You can adjust the number of returned rows using the LIMIT syntax, with a supported range of 1 to 1,000,000. This article introduces the LIMIT syntax format and examples.​
Syntax format​
LIMIT syntax is as follows.​
  • Return the first n rows of data from the calculation results.​
  • ​
    LIMIT n​
    ​
  • Return n rows of data from the calculation results, starting from row s+1; only data from row s+1 onward is read, and the total number of rows read is n.​
  • ​
    OFFSET s LIMIT n​
    ​
The parameters are described below:​
​
Parameter​
Description​
n​
Number of returned data rows. n has a default value of 100, with a valid range of 1 to 1,000,000.​
s​
Start reading from line s+1. The default value of s is 0, and its valid range is 0 to 999,999. That is, reading starts from line 1 by default, and you can start reading from line 1,000,000 at most.​
The sum of s and n should be less than or equal to 1,000,000.​
​
Notice​
When using nested subqueries, the LIMIT syntax is not supported within clauses. For a detailed explanation of nested subqueries, see Nested subquery.​
Syntax example​
Example 1​
  • Scenarios​
  • Count the number of requests for each status code and return the counts for the top three status codes with the highest request numbers.​
  • Query analysis statement​
  • ​
    * | SELECT status, COUNT(*) as PV GROUP BY status ORDER BY PV DESC LIMIT 3​
    ​
  • Query and analysis results​
  • ​Image​​
Example 2​
  • Scenarios​
  • Count the number of requests for each user, and return the data from row 5 to row 9, for a total of 5 rows.​
  • Query and analysis statement​
  • ​
    * | SELECT UID, COUNT(*) AS PV GROUP BY UID OFFSET 4 LIMIT 5​
    ​
  • Query and analysis results​
  • ​Image​​
​
Last updated: 2025.12.12 18:45:50