You can use UPDATE
in tableA
first then delete
duplicate from TableB
as follows:
update tableA A
set A.ref_id =
(select max(ref_id)
from tableB
where name in (select name
from tableB B
where B.ref_id = A.ref_id))
delete from tableB B
where exists
(select 1 from tableB BB
where BB.NAME = B.NAME
AND BB.ref_id > B.ref_id)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…