The following statement would insert the tuples
3,2 (1 replaced by 3) 1,4 (2 replaced by 4) 3,4 (both replaced)
insert into relations_t (id1, id2)
select coalesce(rep1.new_id, id1), coalesce(rep2.new_id, id2)
from relations_t r
left join relations_log_table rep1 on rep1.old_id = r.id1
left join relations_log_table rep2 on rep2.old_id = r.id2
where rep1.id is not null or rep2.id is not null;
If you only want the "best" record (both replaced if this is the case, else one replaced), you must get the top record according to number of replacements.
insert into relations_t (id1, id2)
select top(1) coalesce(rep1.new_id, id1), coalesce(rep2.new_id, id2)
from relations_t r
left join relations_log_table rep1 on rep1.old_id = r.id1
left join relations_log_table rep2 on rep2.old_id = r.id2
where rep1.id is not null or rep2.id is not null
order by case when rep1.id is not null and rep2.id is not null then 0 else 1 end;