hi Jeny
Better way is you fetch all of data to a internal table from db table, then process.
itab1:
name class
X English
X Maths
X English
itab2 add column says 'NUM'.
itab2-name = itab1-name.
itab2-class = itab2-class.
itab2-num = 1.
collect itab2.
sort itab2 by num descending.
read itab2 index 1.
regards,
Archer