Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8617869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:58:17+00:00 2026-06-12T05:58:17+00:00

I’m trying to do a count of nodes connected to node A, where node

  • 0

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:

Book B1
Book B2 CITES B1
Book B3 CITES B1
Book B4
Owner O1 OWNS B1
Owner O2 OWNS B2
Owner O3 OWNS B3 and B4

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.

So first, a query to just list the owners works fine:

start a=node(1) MATCH a<-[:CITES]-b<-[:OWNS]-c return c.name

That returns the names as expected. But then this query:

start a=node(1) MATCH a<-[:CITES]-b<-[:OWNS]-c-[:OWNS]->d return c.name, count(d)

It seems as though it should get to c, which is the list of owners, then go through the OWNS relationship to the owned books as d, and count them. But instead I get:

+--------------------+
| c.name  | count(d) |
+--------------------+
| "O3"    | 1        |
+--------------------+

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:58:18+00:00Added an answer on June 12, 2026 at 5:58 am

    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.

    START a=node(14) 
    MATCH a<-[:CITES]-b<-[:OWNS]-c 
    WITH c MATCH c-[:OWNS]->d 
    RETURN c.name, count(d);
    

    http://console.neo4j.org/?id=x1jst9

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.