So is changing the sub-select to a join a possibility? If not, doing the sub-query first, getting the result in the app code, and then using the result in the second query should dramatically improve results.