I think it may be a combination of a few things . For example, when I delete unwanted items, the merchant keeps the same slot ids, so if he had 80 items and I delete the first 40, he keeps id 40-80 and when I sell him an item, next id is 81. Also, I noticed that most the npcs that lost their items were ones that shared the merchant list with other NPCs. But I think the biggest problem is the lists are too full and need pruning out. I can go in my game and the lower zone i try selling to merchants, the more they hold items. Since Gfay was my first zone I cleaned, all merchants I tried there, hold the items ( and do not share merchant lists). Since I mostly did this in original zones, places like PoK ( iI did not do anything there yet)will not hold items. The items are there in the temp table, just don't show on the vendor(in PoK). You can sell an arrow to the vendor see one arrow in the table then sell another and 2 arrows will show.
So I'm thinking the whole table needs to be cleaned. Before we look at anything else.
I don't have a special sql, I am running batches of sqls when I can ( I wished I would have saved them!) .
Anyway, this time I'm cleaning out all the merchant lists in all the zones.
Merchant lists are loaded into memory ( i think), so it also may be related to the loaded zone and allocated memory for the merchant items - by me lowering the amounts for a given zone, maybe shrinks within range it was intended for. But im talking BS now