Fix an error (syntax error in query) occurred due to empty list of groups