Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find neo4j nodes with more than one incoming relationship

Tags:

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?

like image 800
SteveS Avatar asked Apr 10 '14 20:04

SteveS


People also ask

How do I return all nodes and relationships in neo4j?

When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.

How can I see all nodes in neo4j?

neo4j Share on : The Cypher Query to fetch all nodes of a neo4j graph database. In the neo4j graph database, we use Cypher queries to add and get data. To retrieve all nodes or data points in the neo4j graph database we can use the above Cypher query which will show you all nodes in the graph database.

Can a node have more than one label in neo4j?

Neo4j CQL CREATE a Node Label We can say this Label name to a Relationship as "Relationship Type". We can use CQL CREATE command to create a single label to a Node or a Relationship and multiple labels to a Node. That means Neo4j supports only single Relationship Type between two nodes.

Is it possible for a node to have more than one label?

Create a node with multiple labels. To add labels when creating a node, use the syntax below. In this case, we add two labels.


1 Answers

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; 
like image 176
cybersam Avatar answered Sep 23 '22 06:09

cybersam