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.

Help with Cypher

Hello! I need help with forming a Cypher query

For a graph with 2 types of nodes :User and :Event and 2 types of relationships :OWNS and :PARTICIPATES_IN,

I want to get a list of all events that a user participates in along with the owner of that event and no more that 4 other participants of the same event.

Your help is much appreciated.
Thanks
Sachin

2 REPLIES 2

MuddyBootsCode
Graph Steward

Hello! Welcome to the community.
You could try something like this with Neo4j 4.1 by using a subquery:

MATCH (u:User)-[:PARTICIPATES_IN]->(e:Event)
CALL {
   WITH u, e
   MATCH (u)-[:OWNS]->(e)<-[:PARTICIPATES_IN]-(o:User)
   RETURN o, u LIMIT 4
}
RETURN u, e, o

Not sure if that's exactly how your graph is structured but something along those lines should get it done. Here's an example of something similar in the new docs https://neo4j.com/developer/kb/limiting-match-results-per-row/

Thank you very much!