Sort groups by id