SQLTeam.com | Weblogs | Forums

Query


#1

I have the following table with table names in two fields.

I will provide the start table and the end table. In this case, the start table will be "A" and the end table will be "N". By providing these two values, how would I get all of the blue rows that leads from the path of Table A to Table N?

I was going to do an self join but that would include the red rows.

Table_Name1 Table_Name2 This is not a field
A B Blue
B C Blue
D M Blue
M N Blue
B S Red
S T Red
T U Red
C D Blue

#2

On top of that, there could be multiple paths that leads from A to N.

Table_Name1 Table_Name2 This is not a field
A B Blue
B C Blue
D M Blue
M N Blue
B S Red
S T Red
T U Red
C D Blue
A EE Blue
EE DD Blue
DD N Blue
A VV Red
WW WW Red
YY N Red