fix queries with multiple has clauses