Hi All,
I have a graph with the following relationships:
A -> B -> C & A-> C.
And I want to show All A->C instances including the implied ones (A->B->C).
A union may give you what you want, something like this (still slightly pseudo code, but more cypher like)
MATCH (A)-[:has_ID]->(B)-[:IsEmployedAt]->(C)
return A,C
UNION
MATCH (A)-[:Works_At]->(C)
return A,C
either directly as a list or as input to create the virtual relationships? Though, I suspect you might also want to do a distinct A,C after the UNION to avoid potential duplicates.
The following query might solve your problem:
Match (a:PERSON)-[:WORKS_AT|HAS_ID]->(b)
Optional Match (b)-[:IS_EMPLOYEED_AT]->(c)
Return a.name As PERSON NAME,
Case
When b.name is null
Then b.id
Else b.name
End As COMP/EMP-ID,
c.name As COMPANY NAME
In this query we can use the regular expression operator union over the edge labels to find both company and empid of the person if such relationships in the database exist.
Then the optional match is used to search if node b has an outgoing edge to the company node and the edge label is :IS_EMPLOYED_AT. The optional match returns null if no such edges and subsequent nodes exists.
In case you just wish to visualize the relationships found by the MATCH clause then in the return clause simply return a,b,c