Fix subquery, also don't check query if query is empty