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 query nodes conditioned on another query?

lingvisa
Graph Fellow

For example, I have Product nodes and Category nodes. Some nodes are both Product and Category and created separately, not created with multiple labels.

Product(A)
Category(B)

If A.name = 'Smart Phone' and B.name='Smart Phone'. How to write a query to return all nodes like 'A'? That is, A is a Product, and B is a category, their 'name' property is the same. Based on the same name, I want to find all Product nodes like 'A'.

1 ACCEPTED SOLUTION

Did this request work?

MATCH (n:Product) 
MATCH (m:Category)
WHERE n.name = m.name
RETURN n

View solution in original post

5 REPLIES 5

Hello,

I think this simple request should answer your question:)

MATCH (p:Product) WHERE p.name = "Smart Phone" RETURN p

OR

MATCH (p:Product{name:"Smart Phone"}) RETURN p

Actually, I want 2 queries:

Match (n:Product) 
Match (m:Category)
Where n.name = m.name

Which returns what I want. Any potential issue about that?

Did this request work?

MATCH (n:Product) 
MATCH (m:Category)
WHERE n.name = m.name
RETURN n

That works, except for a typo 'p'. It should be 'm' or 'n', right?

Yeah, sorry:) I updated the answer:)

If that's all, you can accept the message with the answer as an answer to close this topic:)