0

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 |
|  1 |  3 |
|  1 |  5 |
|  4 |  5 |

What it means is that R2 depends on R1 , unidirectionally (R2 -> R1).

The above data means that 1 depends on 2,4,3 directly. And 1 depends on 5 by transitive dependencie, because 1 depends on 4 and 4 depends on 5. So via transitive dependency, 1 and 5 are related but I don't want to show this in my list.

Expected result:

| R1 | R2 |
-----------
|  1 |  2 |
|  1 |  4 |
|  1 |  3 |
|  4 |  5 |

Related links:

  1. SQL query to resolve transitive dependencies in database
  2. transitive reduction algorithm: pseudocode?

Can anyone write a SQL query for this?

Community
  • 1
  • 1

0 Answers0