Without knowing the details of your data structures, at this point, your best bet would b to include indexes on join keys and on where condition variables, as @ChrisNZ suggested.
More importantly, you should reconsider your need to execute this query thousands of times. There is most likely a more efficient way.
... View more