updated query to enforce the groupid