Thanks for your reply jchd. I'm not very familiar with cliques and connected subgraphs but with some helps from wiki I can tell you are right, connected subgraphs is what I'm looking for.
http://en.wikipedia.org/wiki/Connected_component_%28graph_theory%29
http://en.wikipedia.org/wiki/Clique_%28graph_theory%29
I never really thought about using triggers and native SQLite to improve the performance. It was a huge difference between your and Yoriz code even though your used more inputs.
However if both given examples would have been in native C, wouldn't Yoriz be faster, at least the insert since it doesn't update the values on every insert, but slower to get the the output data (search)?
I believe your use of indexes also improves your code some.
Since I have more than 10k accounts in total (if I filter them to only use active accounts I can get down to some hundreds I hope, maybe thousands) I believe there would be a huge performance hit so I'll try to do as much as I can in SQLite like you explained.
I only inserts the values once but might search through it several times, therefore, if my above theory is correct, your code would be to prefer.
I might make some chances to your code to better fit my needs but overall it looks great.
I can't thank you and Yoriz enough for your help.