neo4j - Return common node between 2 different queries -


i want find out common node between 2 different queries. trying hard find out, not think of solution. motive collect top 5 out-degree nodes, collect top 5 root nodes, , return nodes common between top 5 outdegree , root nodes. don't know how merge results because after using "return" option in first query, no further statements executed, without "return" option cannot collect results. (please correct me, if thinking wrong). following queries,

// root nodes match (u:port1)<-[r]-(root) not((root)<--()) return distinct(root.id) node, count(r) outdegree order count(r) desc limit 5  //for outdegree nodes match (n:port1)-[r]->() return n.id node, count(r) outdegree order outdegree desc union match (a:port1)-[r]->(leaf) not((leaf)-->()) return leaf.id node, 0 outdegree limit 5 

how should combine both results, , output of list of nodes common? please me. in advance.

if want intersection between two, don't need unions. collect top 5 in both cases , find intersection.

apoc procedures can here. like:

// root nodes match (:port1)<-[r]-(root) not((root)<--()) // no need distinct since you're aggregating root, count(r) outdegree order outdegree desc limit 5 collect(root) rootnodes // single row  //for outdegree nodes match (n:port1) // more efficient way out degree without needing expand rootnodes, n, size((n)-->()) outdegree order outdegree desc limit 5  rootnodes, collect(n) outdegreenodes apoc.coll.intersection(rootnodes, outdegreenodes) commonnodes  // if needed, unwind , outdegree unwind commonnodes commonnode return commonnode.id node, size((commonnode)-->()) outdegree 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -