in reply to sql adjacency list
Something like this should work, except you'll need to use code specific to your database where I've written the select statements inline.
At this point @old contains the members of Al's component. The code does a breadth-first search. If you prefer depth-first search just change the final push to unshift.@new = ('Al'); while(@new){ $key = shift @new; push @old, $key; @friends = (select col1 from table where col2 = $key, select col2 from table where col1 = $key); %unique = (); @unique{@friends} = undef; delete @unique{@new, @old}; push @new, keys %unique; }
|
|---|