Some people exercise a lot to counteract the impacts of their poor diet, but this isn't optimal for reduring mortality risk, according to a new study. Both a good diet and high levels of physical activity are actually needed.

Maintaining a healthy diet and staying physically active are both important to people's health and longevity. But if your diet isn't exactly ideal, would it be possible to "outrun" your poor diet with high levels of physical activity?

Although a few studies previously demonstrated how exercise could essentially "counteract" the impacts of over-eating, the long-term interaction between diet and physical activity "remained less explored," The University of Sydney said in a news release. In one study, for instance, the overfeeding was only short-term.

For the new study, published in the British Journal of Sports Medicine, the researchers looked at both the independent and combined effects of diet and exercise on "all-cause, cardiovascular disease (CVD) and physical activity, diet and adiposity-related (PDAR) cancer mortality."

They collected data on a sample of 346,627 individuals from the U.K. Biobank study, examining their self-reported moderate-to-vigorous physical activity, diet quality and mortality. A high-quality diet was defined as one that included regular fish, fruits and vegetable portions while having lower red meat and processed meat consumption, the university noted.

The researchers found that high physical activity levels actually could not counteract the impacts of a poor diet, and those who had both high-quality diets and high levels of physical activity had the lowest mortality risk. In fact, their mortality risk was lower by 17% from all causes, 19% from CVD and 27% lower mortality risk from certain cancers compared to those who had the poorest diets and were also physically inactive.

"Adhering to both quality diet and sufficient physical activity is important for optimally reducing the risk of mortality from all causes, CVD and PDAR cancers," the researchers wrote.

In other words, both diet and exercise are needed, and having high levels of physical activity cannot simply counteract the impacts of having a poor diet.

"Some people may think they could offset the impacts of a poor diet with high levels of exercise or offset the impacts of low physical activity with a high-quality diet, but the data shows that unfortunately this is not the case," the study's lead author, Melody Ding of the University of Sydney, said in the university news release. "Public health messages and clinical advice should focus on promoting both physical activity and dietary guidelines to promote healthy longevity."