Sort

  • One column or a list of columns to sort by
  • Each column can be prefixed with:
    • -, for descending order
  • When using prefixes, even a single column needs to be in a list or parentheses. (Otherwise, sort -foo is parsed as a subtraction between sort and foo.)

PRQL

  1. from employees
  2. sort age

SQL

  1. SELECT
  2. *
  3. FROM
  4. employees
  5. ORDER BY
  6. age

PRQL

  1. from employees

SQL

PRQL

  1. from employees
  2. sort [age, -tenure, +salary]

SQL

  1. SELECT
  2. *
  3. FROM
  4. employees
  5. age,
  6. tenure DESC,
  7. salary

PRQL

  1. from employees
  2. sort [s"substr({first_name}, 2, 5)"]

SQL

PRQL

  1. sort tenure
  2. derive name = f"{first_name} {last_name}"

SQL

  1. SELECT
  2. *,
  3. CONCAT(first_name, ' ', last_name) AS name
  4. FROM
  5. employees
  6. ORDER BY
  7. tenure
  • This is an implementation detail of the DB. If there are instances where this doesn’t hold, please open an issue, and we’ll consider how to manage it.
  • Some transforms which change the existence of rows, such as join or group, won’t persist ordering; for example:

PRQL

  1. from employees

SQL