# Query for arranging the nodes by input Hierarchy nodes

**URL:** <https://community.neo4j.com/t/query-for-arranging-the-nodes-by-input-hierarchy-nodes/3149>\
**Category:** Cypher\
**Tags:** browser, cypher, knowledge-base\
**Created:** [November 21, 2018, 8:57am UTC](https://community.neo4j.com/t/query-for-arranging-the-nodes-by-input-hierarchy-nodes/3149 "2018-11-21T08:57:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sucheta](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/sucheta/32/4444_2.png) [@sucheta](https://community.neo4j.com/u/sucheta)\
**Post date:** [November 21, 2018, 8:57am UTC](https://community.neo4j.com/t/query-for-arranging-the-nodes-by-input-hierarchy-nodes/3149/1 "2018-11-21T08:57:01Z")

</div>

Hi,

I want to create a hierarchial graph when i select one .i.e. single values from every relationship. (this is the way i created my UI , where i select one node from every relationship and frame a query ).

The query looks like -

Match (n) OPTIONAL MATCH (n)-[r:Department]-(m),(q)-[a:API]-(b:" +this.FirstValue+ ")  
, (s)-[c:Method]-(d:" + this.secondValue + "), (t)-[e:Parameter]-(f:" + this.thirdValue+ ")"+  
" RETURN n,r,m,q,a,b,s,c,d,t,e,f;

The final query looks like -

Match (n) OPTIONAL MATCH (n)-[r:Department]-(m), (q:claimintimation)-[a:API]-\>(b) , (s:post)-[c:Method]-\>(d), (t:emailAddress)-[e:Parameter]-\>(f) RETURN q,a,s,c,t,e,n,m,r ;

Unfortunately, the output is the entire graph.

 ![api_mining-hierarchy](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/9/949d1fbe53e6a05f2b016b248f5874abc8487fe1.png)

I even tried -

Match (n) OPTIONAL MATCH (n)-[r:Department]-(m:claimintimation), (q:claimintimation)-[a:API]-\>(b:postClai) , (s:postClai)-[c:Method]-\>(d:emailAddress), (t:emailAddress)-[e:Parameter]-\>(f) RETURN q,a,s,c,t,e,n,m,r

But the output is again the entire graph.

How do i make a graph out of the only selective nodes and show its hierarchy
