I'm pretty new to neo4j and I'm not exactly sure how I can achieve this.
Essentially I have 3 sets of nodes: Student, Pass, Mark
Student has a "ACQUIRED" relationship with Pass node. And Student also has an "ACHIEVED" relationship with Mark.
What I want to do, is find all the marks belonging to students who have at least passed once.
This is what I have so far:
MATCH (m:Mark)<-[r:ACHIEVED]-(s:Student)-[a:ACQUIRED]->(p:Pass)
WHERE p.status = 'True'
RETURN m, r, s
The problem with this is that some student nodes have passed multiple times and so they have multiple relationships with the Pass nodes. This makes it so that the marks they achieved get returned multiple times.
For example if one Student node has relationship with 4 Mark nodes and has passed twice (i.e., has relationship with 2 Pass nodes), then the returned output would be 8 Marks instead of 4 - it gets duplicated.
Is there anyway of preventing against this behaviour? and just returning unique results?
Simply add DISTINCT on the RETURN command.
That is:
RETURN distinct m, r, s
Then will remove duplicates for m