Eliminer behovet for at foretage en distinkt ved at aggregere på forhånd
select string_agg(sometext, ' ' order by numval)
from (
select sometext, min(numval) as numval
from t
group by sometext
) s
@Gordons svar
bragte en god pointe. Det er, hvis der er andre nødvendige kolonner. I dette tilfælde en distinct on
anbefales
select x, string_agg(sometext, ' ' order by numval)
from (
select distinct on (sometext) *
from t
order by sometext, numval
) s
group by x