Multiple independent "WITHs"?

I got something like that:

WITH as `aId`, a.acRef as `acRef`
WITH as bId, b.bcRef as `bcRef`
WHERE acRef=c.aRef and bcRef=c.bRef
RETURN aId, bId, as `cId`

but ofcourse it doesn't work because I'm not passing aId and acRef from second subquery to main query. I can do that but then query would execute for really long time (no association between a and b nodes).
Is it possible to make Cypher query with independent subqueries?

Not really sure why you do relational-style joining in a graphdb :slight_smile:

MATCH (a:A) with collect(a) as aNodes
MATCH (b:B) with collect(b) as bNodes
WHERE c.aRef IN [a IN aNodes | a.acRef] and c.bRef IN [b IN bNodes | b.bcRef]
RETURN as `cId`, head(a IN aNodes WHERE c.aRef = a.acRef | ])  as aId, 
head(b IN bNodes WHERE c.bRef = b.bcRef | ])  as bId


MATCH (a:A) 
MATCH (c:C) WHERE a.acRef=c.aRef
MATCH (b:B) WHERE b.bcRef =c.bRef
RETURN as aId, as bId, as cId

depending on the query you should have indexes on the acRef, bcRef and aRef, bRef fields.

Thank you for quick response. I know that I shouldn't join like that :smiley:
I just wondered if I could make temporary sets of nodes to use on later part of the query (like WITH in postgresql).