I'm trying to do a count of nodes connected to node A, where node A is part of a Cypher query starting from node B, and I'm getting unexpected results. Here's an example setup. Pretend we're looking at books and owners, and books cite other books while owners of course own books:

So let's say I'm looking at Book B1, and I want to find each book that cites it, then count the books owned by each person who owns the citing book. So if I start with B1, I should find owners O2 and O3, since each owns a book that cites B1. If I count the books they own, I should get 1 for O2, and 2 for O3.

It feels like it's leaving out the books/nodes that have already been found through the other OWNS link -- the ones represented by b. Is there any way to do this in a single query, or is it best to gather up the owners as c, then query again for each of them? It feels like this should be possible, but I haven't figured it out yet. Any ideas would be great -- thanks in advance.

1 Answer
1

You're right, once a node gets found, you can't find it again in the same match under a different named variable. You can break this up using a WITH, and then use d in the same way, and it will match all of them.

That makes a lot of sense, thanks very much! I'm still encountering a problem, though: when I try that query, I'm getting an error, "SyntaxException: expected return clause" with the indicator at the WITH statement. I'm running neo4j community server 1.7 so it's fairly new, but could it be a cypher parser version issue? Thanks again.
–
MasonoiseOct 4 '12 at 15:39

I answered my own question; indeed, I needed to upgrade my server to version 1.8 and this now works perfectly. Thanks again!
–
MasonoiseOct 4 '12 at 17:39