Again, given the complexity of what you are doing, I'd be sorely tempted to use a stored procedure that would put your results into a TEMPORARY TABLE. So you would call the procedure and then use your own code to JOIN to the temp table created by the procedure.
So long as this is all done on the same open connection, the temporary table will (a) be only visible on that connection and (b) remain available until you drop it or until the connection is closed.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.