Search code examples
cyphermemgraphdb

What is the correct way to count number of nodes using Cypher?


For both of these queries, I get the same result.

Query 1:

MATCH (e:Episode)
RETURN COUNT(e);

Query 2:

MATCH (e:Episode)
WITH COUNT(e) AS count
RETURN count;

What would be the correct way to count the number of nodes?


Solution

  • There's no functional difference for such a simple query. Go with the first option, it is shorter and expresses very clearly what you want.

    If you run both your queries with EXPLAIN or PROFILE, you will see that the executions plans are identical.