For the given multiple nodes find a node

Viewed 30

Without reading all the given User nodes, is there a way to find it by using the given Exam nodes?

Example:

enter image description here

For the given Exam nodes mtech and mca, how would I find the User node?

1 Answers

EDITED: For a given two Exam nodes, you can find the enrolled User node on both Exams (mtech and mca) by doing 1) an undirected match to User node 2) collect the exam names 3) then check if both names mtech and mca are in the collection

 MATCH (u :User) - [ :enrolled] - (e :Exam)
 WHERE e.name in [ 'mtech', 'mca' ]   // assuming that an index is created for Exam.name
 WITH collect(distinct e.name) as exams, u
 WHERE ALL(ex in [ 'mtech', 'mca' ] where ex in exams )
 RETURN u 
Related