How to identify groups/clusters in set of arcs/edges in SQL?

Viewed 376

I have arcs/edges like these ‘haves’:

Node1   Node2
A       B
B       C
D       E

Here A is connected to B and B to C. D is connected to E. In other words there are 2 groups/clusters shown in these ‘wants’:

Node1   Node2   Cluster
A       B       1
B       C       1
D       E       2

Could I use SQL to identify these groups/clusters? I guess this involves self-joins but I cannot see how to write this SQL. Any feedback would be very much appreciated. Thanks!

2 Answers
Related