# Limit results per year in movies example

**URL:** <https://community.neo4j.com/t/limit-results-per-year-in-movies-example/71077>\
**Category:** Neo4j Graph Platform\
**Created:** [October 19, 2024, 9:46am UTC](https://community.neo4j.com/t/limit-results-per-year-in-movies-example/71077 "2024-10-19T09:46:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![f1-outsourcing](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/f1-outsourcing/32/29443_2.png) [@f1-outsourcing](https://community.neo4j.com/u/f1-outsourcing)\
**Post date:** [October 19, 2024, 9:46am UTC](https://community.neo4j.com/t/limit-results-per-year-in-movies-example/71077/1 "2024-10-19T09:46:42Z")

</div>

How should I write this so it only returns at most 20 actors of the top 3 revenue movies in each year?

```auto
  MATCH (a:Actor:Actor)-[r:ACTED_IN]->(m:Movie) 
  WHERE (m.year<1980) 
  RETURN a{id: id(a), labels: labels(a), .name }, m{id: id(a), .title}

```

---

<div class="post-metadata">

**Author:** ![f1-outsourcing](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/f1-outsourcing/32/29443_2.png) [@f1-outsourcing](https://community.neo4j.com/u/f1-outsourcing)\
**Post date:** [October 19, 2024, 10:51am UTC](https://community.neo4j.com/t/limit-results-per-year-in-movies-example/71077/2 "2024-10-19T10:51:50Z")

</div>

I would think this would give me 3 rows 🙂

```auto
MATCH (p:Person)-[:ACTED_IN]->(m:Movie{title:'Mummy, The'})
CALL {
    WITH p
    MATCH (p)
    RETURN p as lp
    LIMIT 3
}
RETURN lp.name, m.title

```

---

<div class="post-metadata">

**Author:** ![f1-outsourcing](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/f1-outsourcing/32/29443_2.png) [@f1-outsourcing](https://community.neo4j.com/u/f1-outsourcing)\
**Post date:** [October 19, 2024, 11:09am UTC](https://community.neo4j.com/t/limit-results-per-year-in-movies-example/71077/3 "2024-10-19T11:09:30Z")

</div>

```auto

MATCH (m:Movie{title:'Mummy, The'})
WHERE m.year=1999 // there are more
CALL {
    WITH m
    MATCH (p:Person)-[:ACTED_IN]->(m)
    RETURN p as lp
    LIMIT 3
}
RETURN lp.name, m.title

```

---

<div class="post-metadata">

**Author:** ![f1-outsourcing](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/f1-outsourcing/32/29443_2.png) [@f1-outsourcing](https://community.neo4j.com/u/f1-outsourcing)\
**Post date:** [October 19, 2024, 1:39pm UTC](https://community.neo4j.com/t/limit-results-per-year-in-movies-example/71077/4 "2024-10-19T13:39:55Z")

</div>

Courtesy of chatgpt, crazy ...

```auto
MATCH (m:Movie)
WHERE m.revenue IS NOT NULL AND m.year IS NOT NULL
WITH m.year AS year, m
ORDER BY year, m.revenue DESC
WITH year, collect(m)[..2] AS tm
UNWIND tm AS hm
MATCH (hm)<-[r:ACTED_IN]-(a:Person)
RETURN year, a.name as nodes, r.role as links, hm.title as nodes2
ORDER BY year

```
