select * from (SELECT @num:=0,@AAA:= 0) temp join ( select @num := if(@AAA = AAA, @num + 1, 1) as row_number, @AAA := AAA as Dummy, mt.* from table1 mt where Created_Time BETWEEN DATE_SUB(CURRENT_TIMESTAMP,INTERVAL 1 DAY) and CURRENT_TIMESTAMP order by AAA, ID desc ) as x where x.row_number <= 3;