I am making a report that pulls data from sales from any date to any date. Currently, it makes about 50 queries. I thought it would make more sense to just have one query, store the results in an array and use that. But that seems to be about the same. Any tips?
50 separate queries certainly seems excessive. While I don't always try to get down to "one query that rules them all," if just for maintainability reasons, I'd certainly consider 50 queries to be a good reason for some refactoring.
Now, as to whether it should be put into one array that you work with or if you can iterate through the result set one at a time, that's more dependent on how your application is structured and precisely what you are trying to do.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks