Traditionally it has been estimated that you should own a home for about 2 years before selling to avoid "losing money." However, it all depends on market conditions. If home prices go up quickly, that number goes down (like over the past year where in many areas home values have gone up close to 10%). Of course, as others said, it also helps to buy in a hot area to make resale easier.
Also, don't count out the possibility of renting your home out when you move. Rental property can be a great investment. The local investors I work with are consistently seeing double digit return on equity. With a short-term purchase such as what you are looking for, it would be my recommendation to buy a house that would perform well as a rental property. Let me know if you are interested in this possibility or just want some more info on real estate investments (or just Raleigh real estate in genera).