Hi,
I have a table in which two fields(FirstID, SecondID) together make the
primary key for the table. Let's look at the following example:
FirstID SecondID
******* ********
2 2
2 3
2 5
5 5
5 7
8 7
9 10
11 12
Here is what I am trying to do. For a given FirstID (say, 2) find all
SecondID with this FirstID (2,3,5). Now for these second ID's is there
a FirstID other than 2? (Yes, 5). I would say FirstID=2 is related to
FirstID = 5. Extending the logic FirstID = 5 is related to FirstID = 8.
I am trying to write a SQL (some kind of self join, I think) which will
give me all related FirstID for a given First ID. For First ID = 2 the
SQL will give me 5 and 8 in the above example. For First ID = 9 the SQL
will give me 11.
Any help will be greatly appreciated. Thanks!!
-Raj
I have a table in which two fields(FirstID, SecondID) together make the
primary key for the table. Let's look at the following example:
FirstID SecondID
******* ********
2 2
2 3
2 5
5 5
5 7
8 7
9 10
11 12
Here is what I am trying to do. For a given FirstID (say, 2) find all
SecondID with this FirstID (2,3,5). Now for these second ID's is there
a FirstID other than 2? (Yes, 5). I would say FirstID=2 is related to
FirstID = 5. Extending the logic FirstID = 5 is related to FirstID = 8.
I am trying to write a SQL (some kind of self join, I think) which will
give me all related FirstID for a given First ID. For First ID = 2 the
SQL will give me 5 and 8 in the above example. For First ID = 9 the SQL
will give me 11.
Any help will be greatly appreciated. Thanks!!
-Raj
Comment