The coronavirus has sent many top stocks into a tailspin in recent weeks. And with health concerns on the rise surrounding COVID-19, companies with exposure to the healthcare industry could be in high demand. Walgreens Boots Alliance (WBA -1.33%) is a well-known pharmacy retailer in the industry, and Walmart (WMT 1.32%) offers many similar products in its stores.

But that's where the similarities end. The two companies' share prices have gone in opposite directions over the past 12 months, with Walmart soundly outperforming both the S&P 500 and Walgreens. Will that trend continue or is Walgreens the better buy from here on out? Let's take a closer look.

Is Walgreens too cheap to pass up?

One of the most appealing things about Walgreens is how cheap the stock is today, trading for about 12 times its earnings. It's a low multiple for a healthcare stock that could see some better days ahead, especially as people ramp up their purchases of household and pharmacy supplies as part of coronavirus-related quarantines and social distancing. The company also offers consumers some attractive delivery options in case they aren't able to visit a store.

Walgreens offers express pickup and delivery, and customers can use the company's app to help get prescriptions efficiently via drive-through, pick-up, or delivery. And eligible purchases on the company's website require no minimum purchase in order to benefit from free shipping.

Medical products in a pharmacy.

Image source: Getty Images.

A coronavirus-fueled surge in traffic could help the pharmacy retailer, which in fiscal 2019 saw its top line grow by a modest 4% from the prior year. But that may not be enough to give its earnings per share much of a boost. Although the company's had no trouble posting a profit over the years, its margins are normally pretty thin, typically less than 3% of its sales. Only twice during the past 10 quarters has Walgreens' profit margin been above 4%.

Walgreens stock is down more than 27% over the past year, performing worse than the S&P 500, which is down 18% over the same timeframe . The decline in price means that its quarterly dividend of $0.4575 is now yielding 3.9% per year, higher than the S&P 500, which typically averages about 2% (although that will be a bit higher now in light of the market's recent declines). Walgreens is a Dividend Aristocrat that has increased its payouts for more than 40 years in a row. With a low multiple, a good dividend, and with what could be a busy couple of quarters coming up, Walgreens may be a cheap stock to buy today.

The company releases its second-quarter results on April 2.

Is Walmart a safe buy amid the market's instability?

Unlike Walgreens, shares of Walmart are up 14% in the past year, soundly beating the market. And unlike the S&P 500, which is down a whopping 32% in the past month, Walmart's down just 3% (Walgreens is down 11% during this time). The versatility and strength of Walmart make it an appealing investment even during such an uncertain time. Regardless of what lockdowns may happen due to the coronavirus, pharmacies and grocery stores are likely to remain open in the U.S., and Walmart's supercenters are going to be key for people to get the supplies that they need.

Walmart offers very convenient delivery options for its customers, and in certain locations, it has free next-day delivery available on orders of $35 or more. And with a wider selection of products than Walgreens, it provides consumers with more of a one-stop shop for their day-to-day needs. The retail giant has also begun offering healthcare services at a couple of its locations in the U.S., and it could be even more of a threat to Walgreens in the future. For now, however, it's unclear how aggressively Walmart will roll out that expansion, if at all.

In its most recent fiscal year, the company saw modest sales growth of 1.9% from the previous year, and higher costs resulted in its operating income declining by 6.3%. Its margins have typically been not much higher than 3%, but with more than $500 billion in annual revenue in each of the past three years, it also doesn't need a large margin to post significant profits.

The stock is a bit more of an expensive buy than Walgreens, trading at about 22 times earnings. It also offers a much more modest dividend which currently yields 1.8% annually. Also a Dividend Aristocrat, Walmart announced in February that it would be raising its payouts for the 47th consecutive year; investors now earn $2.16 per year in dividends for each share of Walmart that they own.

Why Walmart is the better buy today

Walmart's proven to be a more stable buy of late, and that may be reason enough to buy it today. Stability is more important than ever given how volatile the stock market's been. The only negative against Walmart in this comparison against Walgreens is that its dividend is a bit lower and the stock is also at a higher valuation. But with Walmart offering pharmacy services plus a wider range of products than Walgreens, there's much more potential for the company to get a boost as people stock up on supplies out of concern for COVID-19. Paying a premium for Walmart over Walgreens makes sense given that investors get a lot more stability and diversification in return.

Whether you're looking at the short term or the long term, it's hard not to go with Walmart today.