Walmart sales surged in the second quarter.
New York CNN  — 

Target and Home Depot are slumping. But more shoppers are heading to Walmart for groceries and essentials.

Walmart’s sales at stores open for at least a year grew 6.4% last quarter from a year ago, including a 24% increase in online sales. Profit grew 6.7%

The company raised its outlook for the remainder of the year, a signal it expects its strong run to continue.

Walmart’s stock rose 2% during pre-market trading Thursday.

Walmart (WMT) said its grocery sales led the way, increasing by high-single digits last quarter, and the company said it gained market share for groceries from competitors. Walmart (WMT) has been attracting higher-income shoppers than in years past seeking to save money on groceries.

Walmart sells more groceries than competitors, which has helped its sales to be more resilient. Around half of Walmart’s sales come from groceries and other non-discretionary products, while only around a quarter of Target’s sales are from food.

That’s a big benefit as customers eat more food at home and lower-priced items, said Oliver Chen, an analyst at Cowen.

The retailer’s strong results contrast with Target and Home Depot’s weaker figures during their latest quarters. Target’s sales dropped 5.4% last quarter, while Home Depot’s dipped 2%.

Shoppers have pulled back from these chains on discretionary purchases as they face pressure from higher prices and borrowing costs, retailers say.

Walmart also said its discretionary goods like clothing, home goods and sports equipment fell last quarter, although less than expected.

“Food is a strength, but we’re also encouraged by our results in general merchandise versus our expectations when we started the quarter,” Walmart CEO Doug McMillon said.