How about first deleting all values of 11111
where there is a vendor 99999. Then do the
updating on values and rows.
delete t from replenish_vendor t
where vendor_code = 111111 and
exists (select 1 from replenish_vendor
t2 where t2.item_code = t.item_code and
t2.vendor_code = 99999);
update replenish_vendor t
set vendor_code = 99999,
primary_vendor = 'F'
where vendor_code = 111111;
Your text suggests that you want the primary
vendor to be set of
F in this case.
The first delete might need to take into account
If you have any possibility of other database
manipulations happening on the database, you
should wrap these in a single transaction, so
other transactions will not interfere with the