Neo4j Social relationship Query

97 Views Asked by At

I am new to Neo4j. Below is my social graph image which I have created in my Neo4j. Currently I am looking for a Cypher query which will fetch all Friends of "Rohit" who Like "Trekking"

Social Graph

I have tried the following but it is not working.

MATCH (:Profile{name:"Rohit"})-[:Friend]-(p:Profile) 
WITH p 
MATCH (p)-[l:Like]-(:Hobby{name:"Trekking"}) 
RETURN l
1

There are 1 best solutions below

0
On BEST ANSWER

If you want to return the friend you should return p instead of l. Moreover, I think you don't need to use a WITH here (although you can, if you wish), you can try something like

MATCH (:Profile{name:"Rohit"})-[:Friend]->(p:Profile)-[:Like]->(:Hobby{name:"Trekking"}) 
RETURN p

This should work