All Products
Search
Document Center

LIMIT and SIMIT clauses

Last Updated: Aug 05, 2020

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

  1. 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

  1. > SELECT "water_level","location" FROM "h2o_feet" LIMIT 3
  2. name: h2o_feet
  3. time water_level location
  4. ---- ----------- --------
  5. 2015-08-18T00:00:00Z 8.12 coyote_creek
  6. 2015-08-18T00:00:00Z 2.064 santa_monica
  7. 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

  1. > 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
  2. name: h2o_feet
  3. tags: location=coyote_creek
  4. time mean
  5. ---- ----
  6. 2015-08-18T00:00:00Z 8.0625
  7. 2015-08-18T00:12:00Z 7.8245
  8. name: h2o_feet
  9. tags: location=santa_monica
  10. time mean
  11. ---- ----
  12. 2015-08-18T00:00:00Z 2.09
  13. 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

  1. 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

  1. > SELECT "water_level" FROM "h2o_feet" GROUP BY * SLIMIT 1
  2. name: h2o_feet
  3. tags: location=coyote_creek
  4. time water_level
  5. ---- -----
  6. 2015-08-18T00:00:00Z 8.12
  7. 2015-08-18T00:06:00Z 8.005
  8. 2015-08-18T00:12:00Z 7.887
  9. [...]
  10. 2015-09-18T16:12:00Z 3.402
  11. 2015-09-18T16:18:00Z 3.314
  12. 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

  1. > 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
  2. name: h2o_feet
  3. tags: location=coyote_creek
  4. time mean
  5. ---- ----
  6. 2015-08-18T00:00:00Z 8.0625
  7. 2015-08-18T00:12:00Z 7.8245
  8. 2015-08-18T00:24:00Z 7.5675
  9. 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

  1. 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

  1. > SELECT "water_level" FROM "h2o_feet" GROUP BY * LIMIT 3 SLIMIT 1
  2. name: h2o_feet
  3. tags: location=coyote_creek
  4. time water_level
  5. ---- -----------
  6. 2015-08-18T00:00:00Z 8.12
  7. 2015-08-18T00:06:00Z 8.005
  8. 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

  1. > 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
  2. name: h2o_feet
  3. tags: location=coyote_creek
  4. time mean
  5. ---- ----
  6. 2015-08-18T00:00:00Z 8.0625
  7. 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®.