BAC-336: use GROUP BY instead of DISTINCT