select * from table a1 where rowid = ( select max(rowid) from table a2 where a2.id_subject_cost=a1.id_subject_cost and a2.cost=a1.cost )