Taja Jan
Taja Jan

Reputation: 1411

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?

Upvotes: 0

Views: 193

Answers (1)

knittl
knittl

Reputation: 265668

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.

Upvotes: 1

Related Questions