Recursive sub-query handling