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.

Query help

Stuck with a query today and wonder if someone wants to help out?

MATCH (visitor:User)-[:VISIT]->(visit:Visit)-[:VISIT]->(user:User)
WHERE (user.UserId = "xxx")

This is the pattern I am starting with. Want a list of visitors that visited user with UserId. Every Visit has a date and I need to get a list with the 10 last visits, but all those visits need to have unique visitors. Not sure how to use distinct to get what I need

Thanks a lot

1 ACCEPTED SOLUTION

Opted to change the data model so only one visit node is created between 2 users and later updated with number of visits and earlier visits list. Makes sense from many perspectives and means no complicated database queries needed

View solution in original post

3 REPLIES 3

ameyasoft
Graph Maven
Try this:

MATCH (user:User)-[:VISIT]->((visit:Visit)
WHERE (user.UserId = "xxx")
with user, visit

MATCH (visitor:User)-[:VISIT]->(visit)
WHERE visitor.UserId <> user.UserId

RETURN visitor, visit

Thanks a lot for your suggestion Definitely think this could be a step in the right direction but I also need to make sure to return 10 unique visitors only with their last visit based on visit.Date.

Opted to change the data model so only one visit node is created between 2 users and later updated with number of visits and earlier visits list. Makes sense from many perspectives and means no complicated database queries needed