title: Neo4j Cypher query: Sum the results of two queries
body: <p>I have a graph where I have  the following structure:</p>
  
  <p><a href="https://i.stack.imgur.com/vXzPX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vXzPX.png" alt="Sample graph"></a></p>
  
  <p><strong>Nodes:</strong></p>
  
  <ol>
  <li><em>Page</em>(BLUE) -> Page is attached to the lectureseries node and lecture by ownerof relation.</li>
  <li><em>Lecture Series</em>(PURPLE)-> Lectureseries connected to lecture by seriesof relation</li>
  <li><em>Lecture</em> (GREEN)-> lecture connected to page and lectureseries as mentioned above. lecture have property as public, follower, private and privilege
  One of the lecture i.e lect1 is connected to the user by a realtion privileged.</li>
  <li><em>User</em> (RED) (here named Ann) - It is connected to page by follows relation and to 1 lecture mentioned above.</li>
  </ol>
  
  <p><strong>Initial Condition:</strong></p>
  
  <p>We have to show the user all the public and follower lecture always for that we have the perfect query with no problem we get the required result.</p>
  
  <pre><code>MATCH
    (o:page{name:'engg'})-[r:ownerof]-(n:lectureseries)-[s:seriesof]-(l:lecture)
  WHERE l.privacy='public' or l.privacy='follower'
  RETURN DISTINCT n.name as name,n.series_name as title, COUNT(l) AS lecturecount
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <pre><code>name    lecturecount
  
  java    2 (lect3, lect4)
  </code></pre>
  
  <p><strong>Problem:</strong> Now, we have to add those lecture in the count that if the privilege lecture is connected to the user by the relation <strong>privileged</strong></p>
  
  <p>I tried this query:</p>
  
  <pre><code>OPTIONAL MATCH (o:page {name:'engg'})-[r:ownerof]-(n:lectureseries)-[s:seriesof]-(l:lecture)
  WHERE l.privacy='public' or l.privacy='follower'
  RETURN DISTINCT n.name as name, COUNT(l) AS lecturecount
  UNION
  OPTIONAL MATCH (o:page {name:'engg'})-[r:ownerof]-(n:lectureseries)-[s:seriesof]-(l:lecture)-[:privileged]-(u:user {name:'Ann'})
  RETURN DISTINCT n.name as name, COUNT(l) AS lecturecount
  </code></pre>
  
  <p><strong>Results:</strong></p>
  
  <pre><code>name    lecturecount
  
  java    2
  
  java    1
  </code></pre>
  
  <p>But the result should be a single line: java, 3</p>
  
  <p>I searched a lot, ended up to the <code>UNION</code> clause, but it's not helping.</p>
  
  <p><strong>NEW PROBLEM:</strong></p>
  
  <p>How to sum up the <em>result as</em> </p>
  
  <pre><code>seriesname  lecturecount             seriescount    lecturecount
  
  java    2                      AS      2             3
  dotnet  1
  </code></pre>