cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to return all nodes and relationships from a set of nodes?

Given a set of nodes, I want to return all relationships within that set without leaving out any nodes that do not have a relationship in that set.

I have no problem getting all nodes that have a relationship within that set, however, I cannot also include nodes that do not have a relationship within the set.

2 REPLIES 2

ameyasoft
Graph Maven

Hi,

Use OPTIONAL MATCH to get the other nodes. Here is a sample query:

MATCH (a:Actor)-->(m:Movie)-->(d:Director)-->(t:Theater)
OPTIONAL MATCH(b:Actor)
RETURN a, m, d, t, b;

Result:
2X_3_3af9a618be964ab7d0f81ed852194412825be8fd.png

-Kamal

You can use apoc.algo.cover(nodeList) YIELD rel to get all the relationships between a list of nodes.