How to query nodes conditioned on another query?

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'.

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?

1 Like

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