You could try something like this (untested because you did not post DDL, sample data etc):
with OrderedSet
as (
select ro = row_number() over (partition by code order by code asc, id desc)
,t2Id = t2.Id
,t2Code = t2.Code
from t2
)
select *
from t1
join OrderedSet on t1.Id = OrderedSet.Id
where OrderedSet.ro = 1;
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.