All Products
Search
Document Center

Time Series Database:ORDER BY time DESC

Last Updated:Mar 28, 2026

By default, TSDB for InfluxDB® returns query results in ascending timestamp order, with the earliest point first. Add ORDER BY time DESC to reverse this and get the newest points first.

Syntax

SELECT_clause [INTO_clause] FROM_clause [WHERE_clause] [GROUP_BY_clause] ORDER BY time DESC

Usage notes

  • If the query includes a GROUP BY clause, place ORDER BY time DESC after the GROUP BY clause.

  • If the query includes a WHERE clause but no GROUP BY clause, place ORDER BY time DESC after the WHERE clause.

Examples

Return the newest points first

> SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' ORDER BY time DESC

name: h2o_feet
time                   water_level
----                   -----------
2015-09-18T21:42:00Z   4.938
2015-09-18T21:36:00Z   5.066
[...]
2015-08-18T00:06:00Z   2.116
2015-08-18T00:00:00Z   2.064

The query returns points from the h2o_feet measurement in descending timestamp order. Without ORDER BY time DESC, the query returns 2015-08-18T00:00:00Z first and 2015-09-18T21:42:00Z last.

Return the newest points first 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) ORDER BY time DESC

name: h2o_feet
time                   mean
----                   ----
2015-08-18T00:36:00Z   4.6825
2015-08-18T00:24:00Z   4.80675
2015-08-18T00:12:00Z   4.950749999999999
2015-08-18T00:00:00Z   5.07625

The query uses MEAN() and a 12-minute time interval to calculate the average water_level for each window in the specified time range. ORDER BY time DESC returns the latest interval first. Without it, the query returns 2015-08-18T00:00:00Z first and 2015-08-18T00:36:00Z last.

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