title: Neo4j cypher query for getting the number of relationships to a node, for each distinct label
body: <p>I have the following circumstance:</p>
  
  <p>Two types of nodes; <code>NodeA</code> and <code>NodeB</code>. <code>NodeB</code> has numerous different labels (lets, say <code>[LABEL_i, LABEL_j, etc...]</code>), and I want to find the number of relationships (let's say <code>LIKES</code>) from <code>NodeA</code> to <code>NodeB</code> for <strong>each</strong> label on <code>NodeB</code>.</p>
  
  <p>For a single label, I can do the following:</p>
  
  <pre><code>MATCH (a:NodeA {uid: "&lt;id&gt;"})-[r:LIKES]-(b:NodeB:LABEL_i) RETURN count(b) as count
  </code></pre>
  
  <p>For which i get back the number of relationships to <code>NodeB</code> with the label <code>LABEL_i</code>.</p>
  
  <p>I should be able to combine the above logic into a single query to Neo4j, but I can't get it to work, I've tried the following approaches (just fields on the response):</p>
  
  <pre><code>MATCH (a:NodeA {uid: "&lt;id&gt;"})-[r:LIKES]-(b:NodeB) RETURN DISTINCT LABELS(b), count(b), SIZE(LABLES(b)) 
  </code></pre>
  
  <p>But the data I got back from that was not what I was expecting or need, nor can I find other approaches that work, the following are what I tried too</p>
  
  <pre><code>FOREACH (lab in ["LABEL_i", "LABEL_j"] | 
    MATCH (a:NodeA {uid: "&lt;id&gt;"})-[r:LIKES]-(b:lab) RETURN count(b) as count
  )
  Neo.ClientError.Statement.SyntaxError: Invalid use of MATCH inside FOREACH (line 2, column 3 (offset: 49))
  </code></pre>
  
  <p>Any help in how to write this query would be much appreciated, I only recently started using Neo4j.</p>