There are tables:
groups (id, name) с данными: 1 Яблоки 2 Груши 3 Дыни products (id, name, group_id) с данными: 1 Семеринка 1 2 Мелба 1 3 Антоновка 1 products_copy (id, group_id, product_id) с данными 1 2 1 2 3 1 3 2 2 4 2 3
Those. Semerinka apples are also shown in groups of Pears and Melons, Melba and Antonovka in the group of Pears.
The question is how to make a sample of groups with the result 1,2,3. Those. find main group and duplicates from products_copy. You can also use php.