Suggest Actors Query


(Rcfro2) #1

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


(Andrew Bowman) #2

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.