Unfortunately what you're trying to do is not trivial. You would need something like a "reverse nested query" to do this, which has been discussed but is not likely to be implemented in the short term.
There is a suggestion in this topic on how you could rewrite your query logic. Maybe that helps?