Die Syntax wäre folgende:

select ...
from (select distinct ... from myfile where ...)
group by ...
order by ...