Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-24-2021 03:54 PM
In the Querying with Cypher course, in "Limiting the number of intermediate results" (Controlling Results Returned - Querying with Cypher in Neo4j 4.x), the query specifies LIMIT 6
in the WITH
clause. However, in the results posted and what I got experimenting in the Neo4j browser myself, 7 nodes are returned: "Emil Eifrem", "Lawrence Fishburne", "Hugo Weaving", "Carrie-Anne Moss", "Keanu Reeves", "The Matrix", and "The Matrix Reloaded".
Can anyone help me understand what is at play here to make things work this way? Thanks!
Solved! Go to Solution.
02-25-2021 05:02 AM
Hello @emilgerth
Here is the query:
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WITH m, p LIMIT 6
RETURN collect(p.name), m.title
It is placing a limit on the number of Person nodes processed. Once it reaches that limit, the query ends. It returns 6 Person nodes and 2 Movie Nodes
02-25-2021 05:02 AM
Hello @emilgerth
Here is the query:
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WITH m, p LIMIT 6
RETURN collect(p.name), m.title
It is placing a limit on the number of Person nodes processed. Once it reaches that limit, the query ends. It returns 6 Person nodes and 2 Movie Nodes
03-01-2021 11:24 AM
Ah ha! So the LIMIT
only applies to p
in that statement. Thanks so much, that makes way more sense.
03-01-2021 01:02 PM
Almost. LIMIT applies to the number of rows, not necessarily the number of nodes.
You have WITH m, p LIMIT 6
, so you will get 6 rows, each row containing an m
and a p
. It may help to visualize it by returning at that point (a RETURN instead of a WITH on that line, and omit the rest).
After the result rows are limited, the collection happens, where, per m.title
, you collect the names of the associated p
nodes.
All the sessions of the conference are now available online