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.

Suggest Actors Query

rcfro2
Node Clone

Why do the following two queries produce different results with respect to the actor's names? In the second one I am just collecting all the movie titles and for some reason, the actor names change.

match (keanu:Person{name:"Keanu Reeves"})-[:ACTED_IN]->()<-[:ACTED_IN]-(c),
(c)-[:ACTED_IN]->(m)<-[:ACTED_IN]-(others)
where others <> keanu and not ((others)-[:ACTED_IN]->()<-[:ACTED_IN]-(keanu))
return distinct others.name
limit 5

vs

match (keanu:Person{name:"Keanu Reeves"})-[:ACTED_IN]->()<-[:ACTED_IN]-(c),
(c)-[:ACTED_IN]->(m)<-[:ACTED_IN]-(others)
where others <> keanu and not ((others)-[:ACTED_IN]->()<-[:ACTED_IN]-(keanu))
return distinct others.name, collect(m.title)
limit 5

1 ACCEPTED SOLUTION

You're using LIMIT, but not ORDER BY. When no ORDER BY is present the query planner has no restrictions on operations that change the order. Looks like the collecting of movie titles altered the order here, and so your LIMIT got you a different set of results from the results stream.

Use ORDER BY if it's important that your LIMIT gets you to the same set of people between the two queries.

View solution in original post

1 REPLY 1

You're using LIMIT, but not ORDER BY. When no ORDER BY is present the query planner has no restrictions on operations that change the order. Looks like the collecting of movie titles altered the order here, and so your LIMIT got you a different set of results from the results stream.

Use ORDER BY if it's important that your LIMIT gets you to the same set of people between the two queries.