5 pts.
 How to create a loop query in SQL.
Hello Friends,

I am trying to write a SQL code to pull all the parts in a chain. For eg., Part A is replaced by Part B and Part B is replaced by Part C and C to D and so on. Is there anyway that I can pull all the parts in that loop at once. A,B,C,D,.....,
All these relationships are stored in one table X as below:
Part Superseding part
A B
B C
C D
D ...
... ...
... ...
Please help and Thanks in advance !
ASKED: Jan 28, 2009  9:54 PM GMT
UPDATED: May 6, 2010  2:24:59 PM GMT
60,255 pts.

Answer Wiki:
You will probably need to create a function to achieve that, but the syntax will be different depending on the database.

What database are you using ?
Last Wiki Answer Submitted:  Jan 28, 2009  11:22 PM (GMT)  by  Carlosdl   60,255 pts.
To see other answers submitted to the Answer Wiki View Answer History.
Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _




 

See this article for a good discussion on the Oracle “connect by” and “start with” syntax, which could possibly give you the solution:

http://www.oracle.com/technology/products/oracle9i/daily/oct04.html

This lets you chain through records linked like in your data table.

 3,830 pts.