I have a table like below, containing a group_id
and some value.
group_id | value
---------+-------
1 | A
1 | B
2 | C
2 | D
2 | A
3 | E
3 | C
4 | G
4 | H
What I want to get is a unique number for each group that is somehow connected.. like this:
Group 1 and 2 have a common element A, Group 1 and 3 have a common element C > so this is actually one big group.
master_id | group_id | value
----------+----------+--------
1 | 1 | A
1 | 1 | B
1 | 2 | C
1 | 2 | D
1 | 2 | A
1 | 3 | E
1 | 3 | C
2 | 4 | G
2 | 4 | H
How can I get this master_id
?