Our API allows for sorting on all /results endpoints to organize query results in a specified order. This sorting functionality enables users to retrieve data in a manner that best suits their needs, whether ascending or descending. The feature is designed to work in a similar fashion to a SQL ORDER BY clause and is available for the following endpoints:

Sorting can be effectively combined with pagination, filtering and sampling to optimize data retrieval.

Example Sorting Request

curl -X GET "https://api.dune.com/api/v1/query/{{query_id}}/results?limit=100&filters=block_time%20%3E%20'2024-03-05'&columns=tx_from,tx_to,tx_hash,amount_usd&sort_by=amount_usd%20desc,%20block_time" -H "x-dune-api-key: {{api_key}}"

Sorting Parameters

sort_by

  • Type: string
  • Description: Specifies the order in which query results are returned. It directly mirrors the functionality of an SQL ORDER BY clause.
  • Specify the sorting criteria using the format <column_name> asc|desc. For example, block_time desc.
  • If a column name contains special characters, enclose it in double quotes, e.g., "special,column" asc.
  • You can sort by multiple columns by separating them with a comma, exactly like in SQL. For instance, amount_usd desc, block_time.
  • By default, sorting is in ascending order if not explicitly specified. Explicitly include asc or desc to define the sorting order.

Sorted Response