docs-v2/content/influxdb/cloud-dedicated/reference/influxql/limit-and-slimit.md

8.1 KiB

title description menu weight list_code_example
LIMIT and SLIMIT clauses Use `LIMIT` to limit the number of **rows** returned per InfluxQL group. Use `SLIMIT` to limit the number of [series](/influxdb/cloud-dedicated/reference/glossary/#series) returned in query results.
influxdb_cloud_dedicated
name parent
LIMIT and SLIMIT clauses influxql-reference
206 ```sql SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT row_N SLIMIT series_N ```

Use LIMIT to limit the number of rows returned per InfluxQL group. Use SLIMIT to limit the number of series returned in query results.

LIMIT clause

The LIMIT clause limits the number of rows to return from each InfluxQL group. If the query doesn't include a GROUP BY clause, the entire result set is considered a single group. If a query groups data by time, limits are applied after aggregate and selector operations are applied to each time window.

Syntax

SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT N

Arguments

  • N: Maximum number of points to return from each InfluxQL group. If N is greater than the number of points in a group, all points from the group are returned.

Examples

The following examples use the Get started home sensor sample data.

{{< expand-wrapper >}}

{{% expand "Limit the number of rows returned" %}}

SELECT * FROM home LIMIT 3

{{% influxql/table-meta %}} Name: home {{% /influxql/table-meta %}}

{{% influxdb/custom-timestamps %}}

time co hum room temp
2022-01-01T08:00:00Z 0 35.9 Kitchen 21
2022-01-01T08:00:00Z 0 35.9 Living Room 21.1
2022-01-01T09:00:00Z 0 36.2 Kitchen 23

{{% /influxdb/custom-timestamps %}} {{% /expand %}}

{{% expand "Limit the number of rows returned from each InfluxQL group" %}}

SELECT
  MEAN(*)
FROM home
GROUP BY
  time(2h),
  room
LIMIT 3

{{% influxdb/custom-timestamps %}} {{% influxql/table-meta %}} name: home
tags: room=Kitchen {{% /influxql/table-meta %}}

time mean_co mean_hum mean_temp
2022-01-01T08:00:00Z 0 36.05 22
2022-01-01T10:00:00Z 0 36.05 22.549999999999997
2022-01-01T12:00:00Z 0.5 36.25 22.65

{{% influxql/table-meta %}} name: home
tags: room=Living Room {{% /influxql/table-meta %}}

time mean_co mean_hum mean_temp
2022-01-01T08:00:00Z 0 35.9 21.25
2022-01-01T10:00:00Z 0 36 22
2022-01-01T12:00:00Z 0 35.95 22.299999999999997

{{% /influxdb/custom-timestamps %}} {{% /expand %}}

{{< /expand-wrapper >}}

SLIMIT clause

{{% warn %}} InfluxQL is being rearchitected to work with the InfluxDB 3.0 storage engine. This process is ongoing and some InfluxQL features, such as SLIMIT are still being implemented. For more information, see InfluxQL feature support. {{% /warn %}}