SQLFIddle reference for this data.
Suppose I have a table with the 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 |
This means that R1 is connected to R2, bidirectionally. Therefore, if there is an entry for 1.3 in the database, there will be no such entry as 3.1.
According to the above data: 1 is directly related to 2,4,3. And 4 also refers to 1. Thus, through the transitive dependence, 1 and 5 are also considered as related.
Expected Result:
| R1 | R2 | ----------- | 1 | 2 | | 1 | 4 | | 1 | 3 | | 1 | 5 |
Can someone write an SQL query for this?
source share