firm ID Nameproduct ID Name firmIDupdate c set firmID=a.ID from (select Name,min(ID) as ID from firm group by Name)a inner join firm b on a.Name=b.Name inner join Product c on c.firmID=b.ID delete a from firm a where ID not in(select min(ID) from firm where Name=a.Name)
firm
ID Nameproduct
ID Name firmIDupdate c
set firmID=a.ID
from
(select Name,min(ID) as ID from firm group by Name)a
inner join
firm b on a.Name=b.Name
inner join
Product c on c.firmID=b.ID
delete a
from firm a
where ID not in(select min(ID) from firm where Name=a.Name)