Query to find all the nodes that are two steps away from a particular node.

Posted by iecut on Stack Overflow See other posts from Stack Overflow or by iecut
Published on 2010-03-17T01:24:09Z Indexed on 2010/03/17 1:31 UTC
Read the original article Hit count: 316

Filed under:
|
|

Suppose I have two columns in a table that represents a graph, the first column is a FROMNODE and second one is TONODE. What I would like to know is that how will we find all the nodes that are two steps away from a particular node. Lets suppose I have a node numbered '1' and i would like to know all the nodes that are two steps away from it.

I have tried(I am assuming the table name as graph) SELECT FROMNODE FROM GRAPH WHERE TONODE=1 (this is to select all the nodes that are connected to node 1, but I couldn't figure out how would I find all the nodes that are two steps away from node 1??)

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about graph