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

import dotenv, os
from dune_client.types import QueryParameter
from dune_client.client import DuneClient
from dune_client.query import QueryBase

os.chdir("<path_to_your_dotevn_file>")

# load .env file
dotenv.load_dotenv(".env")
# setup Dune Python client
dune = DuneClient.from_env()

query_result = dune.get_latest_result_dataframe(
    query=3567562 # https://dune.com/queries/3567562
    , filters="overtip_amount > 0"
    , columns=["donor_fname","overtip_amount","days_overtipped","overall_tip_given_amount","overall_avg_tip_amount"]
    , sort_by=["overall_tip_given_amount desc"]
) 

print(query_result)

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