cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to return two nodes in a where AND clause

lingvisa
Graph Fellow
MATCH (n:Brand)
WHERE exists (n.ID) and (n)-[]->(p:Product)
RETURN n, p

Find brands which have an ID property and has a relationship with Product node. It shows the error: undefined 'p'. If I remove p and it works.

How to return both n and p in this query?

1 ACCEPTED SOLUTION

Hello @lingvisa

As @Elamaran said, the p variable must be in the MATCH clause:

MATCH (n:Brand)-[]->(p:Product)
WHERE exists (n.ID)
RETURN n, p

You can also specify the relationship types if you know or them 🙂

View solution in original post

2 REPLIES 2

Elamaran
Node Link

You need to have that product node in MATCH clause

Hello @lingvisa

As @Elamaran said, the p variable must be in the MATCH clause:

MATCH (n:Brand)-[]->(p:Product)
WHERE exists (n.ID)
RETURN n, p

You can also specify the relationship types if you know or them 🙂