Hi,
i have two mysql tables: nodes and relations
CREATE TABLE `nodes` (
`id` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `relations` (
`node_id` int(10) unsigned NOT NULL,
`related_node_id` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Lets say there are four rows in nodes: Node 1 and 2 share a relation, 2 and 3, 1 and 4, 4 and 3
INSERT INTO `relations` VALUES (1, 2);
INSERT INTO `relations` VALUES (2, 3);
INSERT INTO `relations` VALUES (1, 4);
INSERT INTO `relations` VALUES (4, 3);
Is there any algorithm to get the paths between the related nodes? Like
+---------+------------------+---------+
| node_id | related_node_id | route |
+---------+------------------+---------+
| 1 | 2 | 1/2 |
| 2 | 3 | 2/3 |
| 1 | 4 | 1/4 |
| 4 | 3 | 4/3 |
| 1 | 3 | 1/2/3 |
| 1 | 3 | 1/4/3 |
+---------+-----------+------+---------+