# Neo4j returning node + subquery results

**URL:** <https://community.neo4j.com/t/neo4j-returning-node-subquery-results/20083>\
**Category:** Newbie Questions\
**Created:** [June 16, 2020, 12:05am UTC](https://community.neo4j.com/t/neo4j-returning-node-subquery-results/20083 "2020-06-16T00:05:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lssayers](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lssayers/32/9299_2.png) [@lssayers](https://community.neo4j.com/u/lssayers)\
**Post date:** [June 16, 2020, 12:05am UTC](https://community.neo4j.com/t/neo4j-returning-node-subquery-results/20083/1 "2020-06-16T00:05:59Z")

</div>

Hi everyone,

What's currently the best approach to returning all nodes of a specific type, plus some results of a subquery for each node?

Essentially I'm wanting to do something like:

```auto
MATCH (m:Movie)
CALL {
  WITH m
  MATCH (p:Person)-[role:ACTED_IN]->(m)
  RETURN p, role
  ORDER BY role.earnings DESC
  LIMIT 1
}
RETURN p.name, role.earnings, m.title

```

However I believe this only looks like it's possible to do (_I'm guessing_) with fabric - it doesn't work in Neo4j browser.

---

<div class="post-metadata">

**Author:** ![elena.kohlwey](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/elena.kohlwey/32/31033_2.png) [@elena.kohlwey](https://community.neo4j.com/u/elena.kohlwey)\
**Post date:** [June 16, 2020, 9:32am UTC](https://community.neo4j.com/t/neo4j-returning-node-subquery-results/20083/2 "2020-06-16T09:32:26Z")

</div>

Hi Louis,  
I think it is much easier (if I correctly understand what you want):

```auto
MATCH (p:Person)-[role:ACTED_IN]->(m:Movie)
WITH max(role.earnings) AS maxRoleEarnings, m
MATCH (p:Person)-[role:ACTED_IN]->(m) 
WHERE role.earnings = maxRoleEarnings
RETURN p.name, role.earnings, m.title

```

So this query gives you the highest paid actor per movie. Is that what you wanted?

Regards,  
Elena

---

<div class="post-metadata">

**Author:** ![lssayers](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lssayers/32/9299_2.png) [@lssayers](https://community.neo4j.com/u/lssayers)\
**Post date:** [June 16, 2020, 10:09pm UTC](https://community.neo4j.com/t/neo4j-returning-node-subquery-results/20083/3 "2020-06-16T22:09:22Z")

</div>

> [@elena.kohlwey](#):
>
> ```auto
> MATCH (p:Person)-[role:ACTED_IN]->(m:Movie)
> WITH max(role.earnings) AS maxRoleEarnings, m
> MATCH (p:Person)-[role:ACTED_IN]->(m) 
> WHERE role.earnings = maxRoleEarnings
> RETURN p.name, role.earnings, m.title
> 
> ```

Thanks Elena,

Yes that's what I was looking for! Appreciate your input.

Cheers,

Louis
