How to mach nodes intersections?

(Nael) #1

Hi there,
If I have a set of nodes that have a unique constraint on the node name and I want to match more than one node by different names and got all the nodes that have relationships to these nodes together. How can I do it?

Example:

Node (Name):
James
Jack
David

Node (Food):
Pizza
Pasta
Sushi

And I have different relationships based on what food everyone like. How can I match the mutual food that only both David and James like?

Thanks

0 Likes

(Ameyasoft) #2

Try something like this:

MATCH (p:Person)-[:LIKES]->(f:Food)
Where p.name = "David"

WITH p, f

MATCH (p1:Person)-[:LIKES]->(f) Where p1.name = "James"

RETURN p.name, p1.name, f.name;

0 Likes