Combine several queries

I'm trying to make some kind of "left join" via Cypher query, but don't know how.
I have two types of Nodes: ACityRep and SourceNode. Via hash-Value (unique ID), I have to find the source node, find the child element and afterwards the hash-value of this child node.

Cypher queries that I want to join:

  1. Finding source node via hash value. Returns source node.
MATCH (a:ACityRep)-[r:SOURCE]->(s:Elements)
WHERE a.hash = "ID_fe2ceb4d-d203-4f70-ade7-bbcae09aa1fc"
RETURN s
  1. Finding child elements for our source node via property "container_id", which points to our source node.
MATCH (n:Elements)
WHERE n.container_id = "122"
RETURN n LIMIT 1
  1. Finding the hash value for our aquired child node
MATCH (a:ACityRep)-[r:SOURCE]->(n:Elements)
WHERE n.element_id = "121"
RETURN a.hash

Thanks in advance!

Hello @VlaD-T and welcome to the Neo4j community :slight_smile:

I don't know how you want to combine your queries, how do you link them (what are the links between them, is a same in 1 and 3) ?

But you can have a look at WITH clause, it will allow you to combine your queries.

Regards,
Cobra

1 Like

Thanks :)
Solved this by following query:

MATCH (a:ACityRep)-[r:SOURCE]->(s:Elements)
WHERE a.hash = "ID_eb1a9f19-3543-44c0-816d-7788ed3dc036"
WITH s
MATCH (n:Elements)
WHERE n.container_id = s.element_id
WITH n
MATCH (a2:ACityRep)-[r2:SOURCE]->(n2:Elements)
WHERE n2.element_id = n.element_id
RETURN a2 LIMIT 1
1 Like