RPV-317

added group by username to sql statement to avoid duplicating. ideally sql needs rewriting to make use of proper objects etc