use GROUP BY instead of DISTINCT in order to re-use the sorting for the distinct operation