in reply to an efficient program?
Depending on your database, it might be more efficient for you to push as much of the grouping and comparisons to the database engine. I can't tell what could be done because your question is pretty vague with regard to the nature of the 'analysis' that you are performing.
If the number of groupings is fairly small, you might consider building result set hashes or arrays for each grouping, so that (for a particular entry with a particular grouping code) you could only visit the result sets that do NOT correspond to the entry's grouping code (as you specified).
Instinctively, I flinch when I see an Order n-squared algorithm -- it seems like there might be a better way to skin this cat, but again, I'm not able to give you advice on this at this level of abstraction, except to say that if you find yourself executing the same database query over and over again, you can sometimes save quite a bit of time building a lookup hash once with a slightly more complex query, and then referring to that hash instead of going to the database over and over.
Of course, you'll want to build statement handles and placeholders for any repetitive query.
|
|---|