I have one table (in MySQL) like this:
subject | predicate | object
A | P1 | X
X | P2 | B
I want to know transitive relation by using this table, so the result should like this:
element1 | predicate1 | pivot | predicate2 | element2
A | P1 | X | P2 | B
I have been tried to construct the query by using nested query, but in the end i have syntax error (I think p2
(in nested query) cannot be determined in main query)
select p1.subject, p1.predicate, p1.object, p2.predicate, p2.object
from some_relation p1
where p1.subject = 'A'
and p1.object = (select p2.subject from some_relation p2 where p2.object = 'B');
Anyone know how to do this kind of query? Is it possible?