I have a table like this
SELECT id, items
FROM ( VALUES
( '1', ARRAY['A', 'B'] ),
( '2', ARRAY['A', 'B', 'C'] ),
( '3', ARRAY['E', 'F'] ),
( '4', ARRAY['G'] )
) AS t(id, items)
Two items belongs to the same group if the have at least one item in common.
For example #1 and #2 belongs to the same group because they both have A and B. #3 and #4 are other different group.
So my desidered output would be
| ID | items | group_alias |
|---|---|---|
| 1 | {A,B} | {A,B} |
| 2 | {A,B,C} | {A,B} |
| 3 | {E,F} | {E,F} |
| 4 | {G} | {G} |
The group_alias field is a new field that say to me that the record #1 and #2 belongs to the same group.
{B,C}or{C}?{B,C}, what wouldgroup_aliaslook like?{A,B},{B,C}and{C,A}, there is no "minimum common item".