Hi Krishna, Here is my take on this.
1. created a graph: <https://lh3.googleusercontent.com/-eVGGJk4fG6c/WXvxtbNQ1XI/AAAAAAAACPk/xnu2MISmN6QDS0TwPLBuLjWT1zq5bfjigCLcBGAs/s1600/kmahi1.png> As you can see nodes "H" and "H1" are the two root nodes. 2. Here is the query and the result to get root nodes match (u:Company)<-[r]-(root) where not((root)<--()) return distinct root.name as Node, count(r) as Outdegree; Result: H and H1 with count 1 each 3. Here is the query and the result for OutDegree nodes for each root node" For H: <https://lh3.googleusercontent.com/-STPjaiifKy4/WXvzmIrPY9I/AAAAAAAACPs/9vGzIV3c2nwTmev2wVBdgd6TfW9L-bz3gCLcBGAs/s1600/kmahi2.png> For H1: <https://lh3.googleusercontent.com/-3PguhoQ6CNM/WXvzsRAcutI/AAAAAAAACPw/mb1NwtQfRoYZlyQPiC-V47JeHvqm-ij2wCLcBGAs/s1600/kmahi3.png> 4.Query to find common nodes MATCH (n:Company {name: "H1"})-[:TO*]->(v) WITH COLLECT (v) as nodes UNWIND nodes as v1 MATCH (n:Company {name: "H"})-[:TO*]->(v1) WITH COLLECT (v1) as nodes UNWIND nodes as v2 RETURN distinct v2.name; <https://lh3.googleusercontent.com/-ROB2yAgxoHU/WXv0UWog_KI/AAAAAAAACP0/3eGq5vOz5a8OirLznG5HxVNe8XYBayUAgCLcBGAs/s1600/Screen%2BShot%2B07-28-17%2Bat%2B07.34%2BPM.PNG> Hope this is what you are looking for. -Kamal On Thursday, July 27, 2017 at 11:34:38 PM UTC-7, Krishna Mahi wrote: > > I want to find out the common node between 2 different queries. I am > trying hard to find out, but could not think of a solution. My motive is to > collect top 5 outdegree nodes, collect top 5 root nodes, and return nodes > that are common between top 5 outdegree and root nodes. I don't know how to > merge the results, because after using "return" option in first query, no > further statements would be executed, but without "return" option we cannot > collect results. (Please do correct me, if I am thinking wrong). Following > are the queries, > // for root nodes > match (u:Port1)<-[r]-(root) > where not((root)<--()) > return distinct(root.id) as Node, count(r) as Outdegree > ORDER BY count(r) desc limit 5 > // for outdegree nodes > match (n:Port1)-[r]->() > return n.id as Node, count(r) as Outdegree > order by Outdegree DESC > union > match (a:Port1)-[r]->(leaf) > where not((leaf)-->()) > return leaf.id as Node, 0 as Outdegree limit 5 > > How should I combine both results, and get the output of list of nodes > that are common? Please do help me. Thanks in advance. > -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
