Skip to main content


The ORDER BY clause allows sorting the data in ascending or descending orders.

Performance considerations

In SQL Frames most clauses of the SELECT statement result in creating a separate DataFrame. However, the ORDER BY operation does not create a separate DataFrame. It is possible to have multiple sorting views of the same DataFrame by first creating a FilteredDataFrame of it using the df.fdf() API as shown in the example above. Such a newly created FilteredDataFrame without any filter will just reference all the rows (data itself is not copied) and hence is independently sortable.

Note that all the projections of a DataFrame created using df.pdf() share the same sorting. This allows navigating multiple views of the same DataFrame by keeping their rows order in sync.

Sort by multiple fields


Sort Prefix

It is possible to specify a sort prefix such that the sort prefix is always in effect and any end user selected sorting is prepended with this sort prefix.

This feature is introduced mainly to support Top N and Others so the Others bucket is always displayed at the end.


Notice how Region doesn't show up in the list of sorted columns as orderBy prefix is implicit.

orderByPrefix() is not supported for projected DataFrames.