Suppose I have a table with following Structure:
create table rd(r1 number,r2 number, primary key (r1,r2));
Sample Data:
| R1 | R2 |
-----------
| 1 | 2 |
| 1 | 4 |
| 2 | 3 |
| 3 | 1 |
| 4 | 5 |
What it means is that R1 is related to R2 , bi-directionally. So if there is an entry in database for 1,3 there won't be an entry like 3,1.
According to above data: 1 is related to 2,4,3 directly. And 4 is related to 1 also . So via transitive dependency, 1 and 5 are also considered as related.
Expected result:
| R1 | R2 |
-----------
| 1 | 2 |
| 1 | 4 |
| 1 | 3 |
| 1 | 5 |
Can anyone write a SQL query for this?