Update master query to do ‘order by’ BEFORE ‘group by’