All Products
Search
Document Center

Time Series Database:LIMIT and SLIMIT clauses

Last Updated:Sep 27, 2023

The LIMIT clause limits the number of returned points for each query, and the SLIMIT clause limits the number of series returned for each query.

LIMIT clause

The LIMIT <N> clause returns the first N points from the specified measurement.

Syntax

SELECT_clause [INTO_clause] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT <N>

Description

N specifies the number of points to return from the specified measurement. If N is greater than the total number of points in a measurement, TSDB for InfluxDB® returns all the points in the measurement. Note that the LIMIT clause must be placed in the order specified in the preceding syntax.

Examples

Limit the number of returned points

> SELECT "water_level","location" FROM "h2o_feet" LIMIT 3

name: h2o_feet
time                   water_level   location
----                   -----------   --------
2015-08-18T00:00:00Z   8.12          coyote_creek
2015-08-18T00:00:00Z   2.064         santa_monica
2015-08-18T00:06:00Z   8.005         coyote_creek

The query returns the three earliest points from the h2o_feet measurement. The three earliest points are determined based on timestamps.

Limit the number of returned points and include a GROUP BY clause

> SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z' GROUP BY *,time(12m) LIMIT 2

name: h2o_feet
tags: location=coyote_creek
time                   mean
----                   ----
2015-08-18T00:00:00Z   8.0625
2015-08-18T00:12:00Z   7.8245

name: h2o_feet
tags: location=santa_monica
time                   mean
----                   ----
2015-08-18T00:00:00Z   2.09
2015-08-18T00:12:00Z   2.077

The query uses an InfluxQL function and a GROUP BY clause. The query returns the average field value of the water_level field key for each tag value in each 12-minute interval that falls within the time range specified in the query. LIMIT 2 indicates that the query requests the average field value of the water_level field key for the two earliest 12-minute intervals in the specified time range. The two earliest 12-minute intervals are determined based on timestamps.

Notes: If the preceding statement does not include the LIMIT 2 clause, the query returns four points for each series. One point is returned for each 12-minute interval in the specified time range.

SLIMIT clause

The SLIMIT<N> clause returns each point from the first N series in the specified measurement.

Syntax

SELECT_clause [INTO_clause] FROM_clause [WHERE_clause] GROUP BY *[,time(<time_interval>)] [ORDER_BY_clause] SLIMIT <N>

Description

N specifies the number of series to return from the specified measurement. If N is greater than the total number of series in a measurement, TSDB for InfluxDB® returns all the series in the measurement. Note that the SLIMIT clause must be placed in the order specified in the preceding syntax.

Examples

Limit the number of the returned series

> SELECT "water_level" FROM "h2o_feet" GROUP BY * SLIMIT 1

name: h2o_feet
tags: location=coyote_creek
time                   water_level
----                   -----
2015-08-18T00:00:00Z   8.12
2015-08-18T00:06:00Z   8.005
2015-08-18T00:12:00Z   7.887
[...]
2015-09-18T16:12:00Z   3.402
2015-09-18T16:18:00Z   3.314
2015-09-18T16:24:00Z   3.235

The query returns all water_level points from one of the series that are associated with the h2o_feet measurement.

Limit the number of the returned series and include a GROUP BY time() clause

> SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z' GROUP BY *,time(12m) SLIMIT 1

name: h2o_feet
tags: location=coyote_creek
time                   mean
----                   ----
2015-08-18T00:00:00Z   8.0625
2015-08-18T00:12:00Z   7.8245
2015-08-18T00:24:00Z   7.5675
2015-08-18T00:36:00Z   7.303

The query uses an InfluxQL function and a time interval specified by the GROUP BY clause to calculate the average field value of the water_level field key for each 12-minute interval in the specified time range. The SLIMIT 1 clause specifies that the query requests a single series that is associated with the h2o_feet measurement.

Notes: If the preceding statement does not include the SLIMIT 1 clause, the query returns the following two series that are associated with the h2o_feet measurement: location=coyote_creek and location=santa_monica.

LIMIT and SLIMIT clauses

If the SLIMIT <N> clause appears after the LIMIT <N> clause in a query, the query returns the first N points from N series in the specified measurement.

Syntax

SELECT_clause [INTO_clause] FROM_clause [WHERE_clause] GROUP BY *[,time(<time_interval>)] [ORDER_BY_clause] LIMIT <N1> SLIMIT <N2>

Description

N1 specifies the number of points to return from the specified measurement. If N1 is greater than the total number of points in a measurement, TSDB for InfluxDB® returns all the points in the measurement.

N2 specifies the number of series to return from the specified measurement. If N2 is greater than the total number of series in a measurement, TSDB for InfluxDB® returns all the series in the measurement.

Note that the LIMIT and SLIMIT clauses must be placed in the order specified in the preceding syntax.

Examples

Limit the number of returned points and series

> SELECT "water_level" FROM "h2o_feet" GROUP BY * LIMIT 3 SLIMIT 1

name: h2o_feet
tags: location=coyote_creek
time                   water_level
----                   -----------
2015-08-18T00:00:00Z   8.12
2015-08-18T00:06:00Z   8.005
2015-08-18T00:12:00Z   7.887

The query returns the three earliest points from one of the series associated with the h2o_feet measurement.

Limit the number of returned points and series, and include a GROUP BY time() clause

> SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:42:00Z' GROUP BY *,time(12m) LIMIT 2 SLIMIT 1

name: h2o_feet
tags: location=coyote_creek
time                   mean
----                   ----
2015-08-18T00:00:00Z   8.0625
2015-08-18T00:12:00Z   7.8245

The query uses an InfluxQL function and a time interval specified by the GROUP BY clause to calculate the average field value of the water_level field key for each 12-minute interval in the specified time range. The LIMIT 2 clause specifies that the query requests the average field value of the water_level field key for the two earliest 12-minute intervals in the specified time range. The two earliest 12-minute intervals are determined based on timestamps. The SLIMIT 1 clause specifies that the query requests a single series that is associated with the h2o_feet measurement.

Notes: If the preceding statement does not include LIMIT 2 SLIMIT 1, the query returns four points for each of the two series associated with the h2o_feet measurement.

InfluxDB® is a trademark registered by InfluxData, which is not affiliated with, and does not endorse, TSDB for InfluxDB®.