in reply to sql adjacency list

If I understand correctly, you're looking for Al's component in the friendship graph, which (assuming friendship is symmetric) is everyone listed in your example.

Something like this should work, except you'll need to use code specific to your database where I've written the select statements inline.

@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; }
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.