Select leaves with subquery instead of array conversion and #select