@trafalgarlaw you can use H2 local database and define rules which item per group will remain by sorting within this group. If you have string variables you could assign numbers that would determine the rank of the item.
Another option would be to create group ranks and then only keep the first one per this group:
