Hi Patrick,
One other possible approach given your current logic would be to index into a result set, say at position 90, by doing SELECT .. FROM .. WHERE .. OFFSET 90 (and if needed, LIMIT if you need a subset).
Hard to say what the performance impact would be, but generally speaking looping with single selects carries more overhead than looping through a cursor. But perhaps it's a useful approach?
Regarding your logic, it may be too much trouble - but if not, I'd be interested to hear what all is required.
If you have to look for a certain count, could you not do something like:
SELECT "JOIN_FIELDS", COUNT(*).. FROM.. GROUP BY.. HAVING COUNT(*) > 5 (as example)
and then join those results?
I've seen a lot of creative ways to solve complex logic with set-processing approaches. Perhaps there's more room for optimization and simplification?