# Query on relationships with Cypher

**URL:** <https://community.neo4j.com/t/query-on-relationships-with-cypher/45946>\
**Category:** Graph Data Science / Graph Analytics\
**Tags:** cypher\
**Created:** [October 16, 2021, 9:42am UTC](https://community.neo4j.com/t/query-on-relationships-with-cypher/45946 "2021-10-16T09:42:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AjejeBrazorf](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@AjejeBrazorf](https://community.neo4j.com/u/AjejeBrazorf)\
**Post date:** [October 16, 2021, 9:42am UTC](https://community.neo4j.com/t/query-on-relationships-with-cypher/45946/1 "2021-10-16T09:42:02Z")

</div>

Hi. I'm learning neo4j and I have to make a simple query, but I'm not able to make it.  
Suppose to have the graph below.  
I want to return all the nodes connected to the node A  
and the maximum of the values on the edges between two consecutive nodes(which is an attribute of the relation). I show an example in the picture below.

I did it for path of length one with this query:

MATCH (p {id:"A"})\<-[r:HAS]-(t)  
RETURN p,max(r.value),t

But I don't know how to make a query for a path longer than one, just because I can't do

MATCH (p {id:"A"})\<-[r:HAS\*]-(t)  
RETURN p,max(r.value),t

I got this error : Type mismatch: expected Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was List  
 ![query](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/5/3/53182787df68a8c5e83ab84f4141f2fd9c2439b5.jpeg)  
 ![query1](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/1/8/18815d41090f4774fe95b10cec2d9cfab9844110.jpeg)

---

<div class="post-metadata">

**Author:** ![AjejeBrazorf](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@AjejeBrazorf](https://community.neo4j.com/u/AjejeBrazorf)\
**Post date:** [October 16, 2021, 10:17am UTC](https://community.neo4j.com/t/query-on-relationships-with-cypher/45946/3 "2021-10-16T10:17:04Z")

</div>

Hello Cobra.  
Thank you for your reply.  
It gives me this error  
"Can't use aggregate functions inside of aggregate functions. "

---

<div class="post-metadata">

**Author:** ![AjejeBrazorf](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@AjejeBrazorf](https://community.neo4j.com/u/AjejeBrazorf)\
**Post date:** [October 16, 2021, 11:36am UTC](https://community.neo4j.com/t/query-on-relationships-with-cypher/45946/5 "2021-10-16T11:36:20Z")

</div>

Yeah I have APOC. But this leads me to the same error I have reported in the question:  
"Type mismatch: expected Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was List\<Relationship"

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [October 16, 2021, 11:49am UTC](https://community.neo4j.com/t/query-on-relationships-with-cypher/45946/6 "2021-10-16T11:49:19Z")

</div>

Hello @AjejeBrazorf and welcome to the Neo4j community 🙂

Sorry, new syntax, I always forget about it.

```auto
MATCH path=(a {id:"A"})<-[:HAS*]-(b)
RETURN a,b, max([r in relationships(path) | r.value])

```

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![AjejeBrazorf](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@AjejeBrazorf](https://community.neo4j.com/u/AjejeBrazorf)\
**Post date:** [October 16, 2021, 12:26pm UTC](https://community.neo4j.com/t/query-on-relationships-with-cypher/45946/7 "2021-10-16T12:26:36Z")

</div>

Thanks a lot. This perfectly works!  
Thanks for your time.

Regards  
Ajeje
