top() function

The top() function sorts each input table by columns and keeps only the top n records. top() is a selector function.

top(n:10, columns: ["_value"])

Empty tables

top() drops empty tables.



(Required) Number of records to return.


List of columns to sort by. Sort precedence is determined by list order (left to right). Default is ["_value"].


Input data. Default is piped-forward data (<-).


The following example uses data provided by the sampledata package to show how top() transforms data.

Return rows with the top three values in each input table
import "sampledata"
    |> top(n: 3)

View input and output

Was this page helpful?

Thank you for your feedback!

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.