I am struggling to find an optimal solution for the following problem. Suppose I have a table \'Table\' like this:
id name report_id 1 name1 1
SQLFiddle demo
select ID,NAME,REPORT_ID from ( select *, @row:=if(name=@name,@row,0)+1 as rn, @name:=name from (select *,RAND() as trand from t) t1, (select @row:=0,@name:='') tm2 order by name,trand ) t2 where rn<=10