MySQL: using UNION vs multiple queries

Viewed 8366

I'm interested to know if a UNION is better than running multiple queries.

If so, are there times that multiple queries would be faster or preferred for other reasons?

2 Answers

You ask if it "is better" - I assume you are referring to "performance-wise"?

If the speed impact is minimal, you might want to prefer multiple queries to keep your code more readable; instead of dealing with multiple queries, doing different things, in one union.

Depends on the use case, for sure. But readable and understandable code might have it's worth in a bigger project in the long term

Related