Sort

Orders rows based on the values of one or more columns.

sort [{direction}{column}]

Parameters

  • One column or a list of columns to sort by
  • Each column can be prefixed with:
    • +, for ascending order, the default
    • -, for descending order
  • When using prefixes, make sure to wrap columns in a list. Otherwise, sort -column is interpreted as subtraction between sort and column.

Examples

PRQL

from employees
sort age

SQL

SELECT
  employees.*
FROM
  employees
ORDER BY
  age

PRQL

from employees
sort [-age]

SQL

SELECT
  employees.*
FROM
  employees
ORDER BY
  age DESC

PRQL

from employees
sort [age, -tenure, +salary]

SQL

SELECT
  employees.*
FROM
  employees
ORDER BY
  age,
  tenure DESC,
  salary

Roadmap

Currently sort does not accept expressions:

from employees
sort [s"substr({first_name}, 2, 5)"]  # Currently will fail