select DISTINCT (regexp_split_to_array(commend, E'\\s+'))[:3] from orders ORDER BY (regexp_split_to_array(commend, E'\\s+'))[2];ОШИБКА: в конструкции SELECT DISTINCT выражения ORDER BY должны быть в списке выборки
select * from (
select DISTINCT (regexp_split_to_array(commend, E'\\s+'))[:3] as words from orders
) t
order by words[2]SELECT DISTINCT (regexp_split_to_array(commend, E'\\s+'))[:3] AS first_3_words
FROM orders
ORDER BY first_3_words[2];