remove duplicate memberships with distinct and order by group id