cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j returning node + subquery results

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:

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.

1 ACCEPTED SOLUTION

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

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

View solution in original post

2 REPLIES 2

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

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

Thanks Elena,

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

Cheers,

Louis