Distinct
PRQL
SQL
SELECT
DISTINCT department
FROM
employees
This also works without a linebreak:
PRQL
from employees
select department
group department (take 1)
SQL
# youngest employee from each department
from employees
sort age
take 1
)
SELECT
*,
ROW_NUMBER() OVER (
PARTITION BY department
ORDER BY
age
) AS _expr_0
FROM
employees
)
SELECT
*
FROM
table_1 AS table_0
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:
WITH table_1 AS (
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY first_name, last_name) AS _expr_0
FROM
employees
)
SELECT
*
FROM
table_1 AS table_0
WHERE
_expr_0 <= 1
# youngest employee from each department
from employees
group department (
sort age
)
… to …