Thanks for all your help so far.
This is one way I've tried and it works I think but I'm sure you clever folks can come up with a better way :
declare @pairs table (dropped_id int, retained_id int)
insert into @pairs
SELECT 34336, 14553 UNION ALL
SELECT 39352, 14553 UNION ALL
SELECT 39352, 34336 UNION ALL
SELECT 39776, 34123 UNION ALL
SELECT 47833, 14553 UNION ALL
SELECT 47833, 34336 UNION ALL
SELECT 47833, 39352 UNION ALL
SELECT 47969, 14553 UNION ALL
SELECT 47969, 34336 UNION ALL
SELECT 47969, 39352 UNION ALL
SELECT 47969, 47833 UNION ALL
SELECT 48460, 14553 UNION ALL
SELECT 48460, 34336 UNION ALL
SELECT 48460, 39352 UNION ALL
SELECT 48460, 47833 UNION ALL
SELECT 48460, 47969 UNION ALL
SELECT 48463, 14553 UNION ALL
SELECT 48463, 34336 UNION ALL
SELECT 48463, 39352 UNION ALL
SELECT 48463, 47833 UNION ALL
SELECT 48463, 47969 UNION ALL
SELECT 48463, 48460 UNION ALL
SELECT 52149, 14553 UNION ALL
SELECT 52149, 34336 UNION ALL
SELECT 52149, 39352 UNION ALL
SELECT 52149, 39776 UNION ALL
SELECT 52149, 47833 UNION ALL
SELECT 52149, 47969 UNION ALL
SELECT 52149, 48460 UNION ALL
SELECT 52149, 48463 UNION ALL
SELECT 54497, 14553 UNION ALL
SELECT 54497, 34336 UNION ALL
SELECT 54497, 39352 UNION ALL
SELECT 54497, 39776 UNION ALL
SELECT 54497, 47833 UNION ALL
SELECT 54497, 47969 UNION ALL
SELECT 54497, 48460 UNION ALL
SELECT 54497, 48463 UNION ALL
SELECT 54497, 52149 UNION ALL
SELECT 66316, 14553 UNION ALL
SELECT 66316, 34336 UNION ALL
SELECT 66316, 39352 UNION ALL
SELECT 66316, 47833 UNION ALL
SELECT 66316, 47969 UNION ALL
SELECT 66316, 48460 UNION ALL
SELECT 66316, 48463 UNION ALL
SELECT 66316, 48819 UNION ALL
SELECT 66316, 52149 UNION ALL
SELECT 66316, 54497 UNION ALL
SELECT 74054, 66316 UNION ALL
SELECT 77722, 53333
declare @sortedpairs table (retained_id int, dropped_id int)
insert into @sortedpairs (retained_id,dropped_id )
select retained_id ,dropped_id from @pairs where retained_id <dropped_id
insert into @sortedpairs (retained_id,dropped_id )
select dropped_id ,retained_id from @pairs where retained_id >dropped_id
insert into @sortedpairs (retained_ID,dropped_ID)
select sp1.retained_ID,sp2.retained_ID from @sortedpairs sp1
inner join @sortedpairs sp2
on sp1.dropped_ID=sp2.dropped_ID
and sp1.retained_ID<>sp2.retained_ID
and sp1.retained_ID<sp2.retained_ID
insert into @sortedpairs (dropped_ID,retained_ID)
select sp1.retained_ID,sp2.retained_ID from @sortedpairs sp1
inner join @sortedpairs sp2
on sp1.dropped_ID=sp2.dropped_ID
and sp1.retained_ID<>sp2.retained_ID
and sp1.retained_ID>sp2.retained_ID
while (@@rowcount<>0)
begin
update tab1 set tab1.retained_ID=tab2.retained_ID
from @sortedpairs tab1
inner join @sortedpairs tab2
on tab2.dropped_ID=tab1.retained_ID
end
select * from @sortedpairs
group by retained_ID,dropped_ID
order by 1
---------------------------------------------------------
It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
David Edwards - Media lens[/url]
Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
Howard Zinn