title: How do I match nodes on all matching connections?
body: <p>I'd like to return all encounters (p2) that have the same ICD9DX codes as the p1:Encounter. So if p1 has 3 ICD9DX codes, I'd like to find p2 nodes that have those same 3 codes. Ultimately I'd like to know how to write the query so it will return just p2 nodes that <strong>only</strong> have those same three codes and also how to write it so that it will return ones that have <strong>at least</strong> those three codes. I've tried figuring this out from the other questions that have been answered, but have been unsuccessful so far. Below is my latest iteration. </p>
  
  <pre><code>MATCH path=((p1:Encounter {PatientAccount: '1003149560'})-[:HasICD9Dx]-(i:ICD9DX)-[:HasICD9Dx]-(p2:Encounter))
  WHERE ALL(p1 in tail(nodes(path)) WHERE ()-[:HasICD9Dx]-&gt;p1) 
  RETURN p2
  </code></pre>
  
  <p>I'm brand new to Neo4j, so any commentary on the logic would be helpful. I've seen other posts that approach similar topics using WITH, but I'm struggling to understand the WITH clause. Maybe I just need to dig in and read the manual.</p>