Replace DISTINCT clause with GROUP BY.