How to return two nodes in a where AND clause

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?

You need to have that product node in MATCH clause

Hello @lingvisa :slight_smile:

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 :) :wink: