Hi, I've been thinking a lot on the problem and finally decided to write about my problem to the list.
Let's say we have a table: create table friends( id int(10) unsigned not null auto_increment, friend1 int(10) unsigned not null, friend2 int(10) unsigned not null, primary key(id), foreign key(friend1) references users(id) on delete cascade, foreign key(friend2) references users(id) on delete cascade )engine=innodb; This table describes connections between users. So if we have there friend1 = 2 , friend2 = 3 then it means that a user( id = 2 ) is a friend with user( id = 3 ) and user( id = 3 ) is a friend with user( id = 2 ), it's like a graph with undirected edges. The main problem i cannot solve is: try to find a connection between users. So if you are asked if there is a connection between users with id = 2 and id =7 and we have such edges: 1 4 2 5 3 7 5 9 5 3 4 9 then the answer is 2 5 3 7 Is there a way to write a stored procedure ( or another way ) in order to get this connectivity ( get the path from id = 2 to id = 7 ) ? Don't know if it makes things easier but we can stop searching if the depth of connectivity is more than 5... Thx, Konstantin