In 2005, Berkshire Hathaway (NYSE:BRK.A) (NYSE:BRK.B) chief Warren Buffett began buying shares of Wal-Mart Stores, Inc. (NYSE:WMT).

At the time, Wal-Mart seemed to embody many of the qualities Buffett looks for in a stock. With its size and scale, Wal-Mart could certainly claim the "economic moat" that Buffett favors, as it had put many independent retailers out of business during its rampant expansion. After trading sideways for several years, the stock was as cheap as it had been in at least a decade. And the company had shown its commitment to shareholders as a Dividend Aristocrat, raising its dividend payout every year for at least 25 years.

Berkshire Hathaway CEO Warren Buffett

Image source: The Motley Fool.

Indeed, the retail giant was flying high back in 2005. Earnings per share grew 11% that year, on a 3% increase in comparable sales in the U.S., and its retail square footage jumped 14%, thanks in part to an acquisition in Brazil.

Fast-forward a decade and things have changed. Wal-Mart's growth has ground to a halt as it is besieged by (NASDAQ:AMZN) and other online retailers, and Buffett has taken notice, dumping nearly all of his stake in Wally World last year. After selling much of its position in prior quarters, Berkshire sold $900 million worth of Wal-Mart shares in the fourth, more than 90% of its remaining stake.

As the chart below shows, the broad-market S&P 500 more than doubled the returns of Wal-Mart during the period when Buffett owned the stock:

WMT Chart

WMT data by YCharts.

In other words, Wal-Mart was a clear loser for the Oracle of Omaha. Let's look for a few takeaways from Buffett's losing bet on Wal-Mart.

1. Sustainable competitive advantages can change

For years, Buffett has told investors that one of the most important factors he looks for in a stock is a "sustainable competitive advantage." This can be anything from a brand name to a distribution network to a strong reputation, but it gives that business an ability to charge higher prices than competitors, and presents a barrier to entry to rivals.

For years Buffett has favored big-brand stocks such as Coca-Cola and Kraft Heinz Company, so it's no surprise he invested in Wal-Mart. Not only is the retailer a big brand, but its size also gave it economies of scale that its competitors couldn't match. Today, the company is still the world's largest by revenue.

But some things happened in the last ten years that undermined Wal-Mart's competitive advantage. E-commerce companies like Amazon have increasingly taken sales from Wal-Mart as shopping patterns shift to the internet. And to a lesser extent, Costco Wholesale (NASDAQ:COST) has stolen Wal-Mart's banner as the low-price operator.

As the chart below shows, Amazon's revenue has grown much faster than Wal-Mart's, and even Costco's growth has doubled that of its larger rival:

WMT Revenue (TTM) Chart

WMT Revenue (TTM) data by YCharts.

Today, it seems that Amazon and Costco have competitive advantages over Wal-Mart.

2. Leadership matters

Though Buffett prefers companies that are so strong they could be run by anyone -- he famously once said even a ham sandwich could run Coke -- the difference between winners and losers in the stock market often comes down to who's in charge.

Since Buffett first bought Wal-Mart, the company has had three different CEOs, and its strategy has changed several times. Though the company recognized the opportunity in e-commerce early on, it was slow to take advantage of it.

Amazon's Jeff Bezos has built his business around that opportunity, and the company has aggressively expanded to provide faster delivery and add benefits to its Prime membership service. Buffett recognized Bezos last May, calling him a "genius" and saying, "We haven't seen many businessmen like him." That pronouncement seemed to foreshadow his selling of Wal-Mart as he realized it had been bested by Bezos and Amazon.

3. No one bats 1.000 in investing

It's been said about baseball that even the best players make outs most of the time they step up to the plate. Investing is similar. Even the best pick plenty of losers.

Wal-Mart is far from alone among Buffett's bad bets. IBM has significantly underperformed the market since Berkshire began buying it a few years ago. Buffett has also admitted mistakes on companies such as Tesco PLC and Dexter Shoe Company.

But part of Buffett's genius is that Berkshire has avoided the steep losses that plague the market during recessions: It's during those periods that his company has most outperformed the market. In the case of Wal-Mart, Buffett seemed to recognize that circumstances had changed since he first bought the stock in 2005. He still pocketed a gain on the stock, just less than an index fund would have yielded.

As evidence of his always-evolving approach to investing, in the recent quarter, Buffett bought shares in a sector he had panned just a few years ago: airlines. That shows that it's never too late to refine your investing philosophy.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.