Distinct

PRQL

SQL

  1. SELECT
  2. DISTINCT department
  3. FROM
  4. employees

This also works without a linebreak:

PRQL

  1. from employees
  2. select department
  3. group department (take 1)

SQL

  1. # youngest employee from each department
  2. from employees
  3. sort age
  4. take 1
  5. )

  1. SELECT
  2. *,
  3. ROW_NUMBER() OVER (
  4. PARTITION BY department
  5. ORDER BY
  6. age
  7. ) AS _expr_0
  8. FROM
  9. employees
  10. )
  11. SELECT
  12. *
  13. FROM
  14. table_1 AS table_0
  15. WHERE

Note that we can’t always compile to DISTINCT; when the columns in the aren’t all the available columns, we need to use a window function:

  1. WITH table_1 AS (
  2. SELECT
  3. *,
  4. ROW_NUMBER() OVER (PARTITION BY first_name, last_name) AS _expr_0
  5. FROM
  6. employees
  7. )
  8. SELECT
  9. *
  10. FROM
  11. table_1 AS table_0
  12. WHERE
  13. _expr_0 <= 1

  1. # youngest employee from each department
  2. from employees
  3. group department (
  4. sort age
  5. )

… to …