Query help

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

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

Thanks a lot :pray:

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 :heart_eyes: 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 :slightly_smiling_face: