# Help with creating a query that will return only the relavant nodes and the relavent relationships

**URL:** <https://community.neo4j.com/t/help-with-creating-a-query-that-will-return-only-the-relavant-nodes-and-the-relavent-relationships/60148>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated\
**Created:** [July 25, 2022, 6:36am UTC](https://community.neo4j.com/t/help-with-creating-a-query-that-will-return-only-the-relavant-nodes-and-the-relavent-relationships/60148 "2022-07-25T06:36:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![verachkaverachk](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/verachkaverachk/32/23510_2.png) [@verachkaverachk](https://community.neo4j.com/u/verachkaverachk)\
**Post date:** [July 25, 2022, 6:36am UTC](https://community.neo4j.com/t/help-with-creating-a-query-that-will-return-only-the-relavant-nodes-and-the-relavent-relationships/60148/1 "2022-07-25T06:36:50Z")

</div>

**Hello everyone!**

I hope you could help me with an issue i'm trying to figure out.

i'm trying to show my graphs in the most comfortable way I can in neodash and in neo4j as well.

for example I have these 2 graphs.

What I want from them is to see in each only the dark green color(SubGraphInstance), the label FROM GRAPH to my orange nodes(CellInstances), from (CellInstance-orange nodes) I want to see the red nodes(Functions of these cellIntsances) with the relationship CELL\_TYPE(from orange to red node), in addition I want to see from the orange node the relationship FROM\_CELL, to another orange node with relationship TO\_CELL.

my purpose is to to get rid of all the additional nodes like the connection(beige) nodes, and the variables of the red functions and their relationships

without damaging my entities. and to be able to see all as a graph

When I tried to do merge with the following cypher , I couldn't add to the changed graph anything, couldn't make calculations or connect it to another graph.

**MATCH (a1:CellType{transformType:'ANALOG\_TO\_ANALOG'}), (a2:Function {expression:"x+y"}), (a3:Variable {variableName:'x'}),(a4:Variable {variableName:'y'})**

**WITH head(collect([a1,a2,a3,a4])) as nodes**

**CALL apoc.refactor.mergeNodes(nodes,{properties:"combine", mergeRels:true}) yield node**

**Return node;**

then, I tried these too options that were better becuse my data wasn't merged.

**MATCH (a:SubGraphInstance) where a.name = "alpha1"  
CALL apoc.path.spanningTree(a,{maxLevel:5}) YIELD path  
RETURN path**

AND this as well

**MATCH p = (g:SubGraphInstance)-[:FROM\_GRAPH]-\>(o:CellInstance)-[\*10]-(r:Function)**

**RETURN p**

![verachkaverachk_0-1658730139115.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/3/4/3485cab78bf919fb1885dfb8e01eacd5c5d42b46.png "verachkaverachk\_0-1658730139115.png")

![verachkaverachk_0-1658731928473.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/5/6/562e51dd641bd9c8eb6e554e3777501444ab44c4.png "verachkaverachk\_0-1658731928473.png")

If there is a way to merge the data without damaging it then it will be good as well,

my ideal graph in general looked like this drawing:

![verachkaverachk_1-1658730740679.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/a/2/a2e8c6bdb32aec0b8b1dc3963ca38a4f271aec76.png "verachkaverachk\_1-1658730740679.png")

Vera.
