Here are syntactically correct Oracle statements
update table1 t1
set t1.table2_id = (
select new_id
from (
select id, min(id) over (partition by name) new_id
from table2
) d
where d.id = t1.table2_id
);
delete from table2
where id not in (
select min(id) from table2 group by name
);
The analytic function min(id) over (partition by name)
is used here so that you can have all original ids together with their new ids (the min ids from the set where the name
is the same).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…