To rephrase what I and Lews said;
If you leave an NPC for a certain time (varies a bit between NPCs) their inventory will be reset.
If you come back before that happens and hit alt or talk to the person, you will need to wait the full reset time again. Talking to someone every 5 minutes, their inventory will never reset.
Also, merchants can keep some of the items you sell them, particularly quest items and some magic items. These show up at the top of the inventory list, so with enough of them accumulated you might not be able to see that the rest of the inventory has changed without scrolling down.