'Cypher: get all the relationships of node with a specific relationship

I'm trying to find all the relationships of the nodes which have one specific relationship. People can be connected to events which in turn are connected to churches. I'm interested in the people who are connected as witnesses to events (marriages) in the following manner:

(p:person)-[:ACTED_AS_BEKENDE]-(e:event)

What I'm struggling with is that when I write a simple MATCH statement with a WHERE clause (see below), I only get the events to which people were connected via this specific relationship.

MATCH (p:person)--(e:event)--(c:church)
WHERE (p:person)-[:ACTED_AS_BEKENDE]-(e:event)
RETURN distinct p.ID AS ID, p.Name AS NAME, labels(e) AS Event_name, e.Event_year AS year, labels(c) AS Church ORDER BY e.Event_year ASC

To reiterate: I need a query which first selects the people who are tied to events via the [:ACTED_AS_BEKENDE] edge and then retrieves all the events to which these people were tied.



Solution 1:[1]

Do you need something like this?

MATCH (p:person)-[:ACTED_AS_BEKENDE]-(:event)
WITH p
MATCH (p)--(e:event)--(c:church)
RETURN distinct p.ID AS ID, p.Name AS NAME, labels(e) AS Event_name, e.Event_year AS year, labels(c) AS Church ORDER BY e.Event_year ASC

This will first find all persons that are ACTED_AS_BEKENDE, and for them it will fins the events and churches as you wanted

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nimrod serok