25

I'm trying to find all the nodes with more than one incoming relationship. Given this data:

a-[has]->b
a-[has]->c
d-[has]->b

So, I'm looking for a query that returns 'b', because it has more that one incoming.

This query is close. It returns 'a' and 'b', because they both have 2 relations:

match (n)--()
with n,count(*) as rel_cnt
where rel_cnt > 1
return n;

However, this query (the addition of '-->') doesn't return any and I don't know why:

match (n)-->()
with n,count(*) as rel_cnt
where rel_cnt > 1
return n;

Am I going about this all wrong?

SteveS
  • 536
  • 1
  • 6
  • 10

1 Answers1

44

Does this work for you?

MATCH ()-[r:has]->(n)
WITH n, count(r) as rel_cnt
WHERE rel_cnt > 1
RETURN n;

I am assuming, perhaps incorrectly, that 'has' is the appropriate relationship type. If not, then try:

MATCH ()-[r]->(n)
WITH n, count(r) as rel_cnt
WHERE rel_cnt > 1
RETURN n;
cybersam
  • 63,203
  • 6
  • 53
  • 76
  • Thanks, both your queries work and my original. It turns out I wasn't creating the nodes correctly and I had 2 nodes named a. A newbie mistake I suppose. – SteveS Apr 10 '14 at 20:45