-2
To get max(id) for each numberExtern, select with group by
Example:
select
    max(ID),
    NUMEROEXTERNO
from
    BA_COBAN.DETALHELOJAARQCADASTRAL
where
    NUMEROEXTERNOMATRIZ = '50494'  
Now use this select to do the select you already have to do the Insert in the table, so it will filter only the max of each external number.
Example:
select
    *
from
    (select
         max(ID),
         NUMEROEXTERNO
     from
         BA_COBAN.DETALHELOJAARQCADASTRAL
     where
         NUMEROEXTERNOMATRIZ = '50494') X
inner join BA_COBAN.DETALHELOJAARQCADASTRAL DE on DE.ID = X.ID  

"wanted to select only max(id) of each numberExtern" this does not make sense "of each numberExtern", if it is max will be of all, otherwise it would not be a max. as to insert in another table only do Insert with select or select into
– Ricardo Pontual
I’ll rephrase my question.
– Diego Garcia