Restore outer query result after inner query