make having and limitspec work for nested queries