Hi Everyone!
I need some help with building a Cypher query for my problem.
Given the following schema:
I want to fetch all the children(blue/yellow node), parents(yellow node), and the respective properties(gray node) of their location(green node). Basically, have the following output at the end:
Parent (yellow node) | Child (yellow/blue) | Parent_property(gray) | Child_property(gray) |
---|
For that, I used UNION to get parent_ids/child_ids from the yellow and blue nodes under same column names, and built 2 separate CALL subqueries (one to fetch id information, and the other for property information). However, I don't know how to proceed next, since I obtained duplicated information after executing the cypher query as it now. I understand that this is due to how CALL subqueries work, however, I don't know how to fix that.
//Fetch all parent and children ids
CALL {
MATCH (c:subPart)<-[:Has_child]-(p:mainPart{id: "12345"}) RETURN c.id AS child, p.id AS parent
UNION
MATCH (m:mainPart)<-[:Has_child]-(p:mainPart {id: "12345"}) RETURN m.id AS child, p.id AS parent
}
MATCH (p)-[]->(r)-[:Has_property]->(property1)
CALL {
MATCH (c)-[]->(k)-[:Has_property]->(property2) RETURN property2.name AS child_property
UNION
MATCH (m)-[]->(n)-[:Has_property]->(property3) RETURN property3.name AS child_property
}
RETURN child, parent, property1.name AS parent_property, child_property
I have also tried to COLLECT parent/ child ids and properties in lists and then UNWIND them, or use the WHERE EXISTS{} clause to filter for the properties, but none of this worked.
I am using Neo4j Desktop 4.3.3 version.
Any help/tips will be very much appreciated! Thank you!