user479947
user479947

Reputation:

Match all nodes and return nodes + relationships

In the latest version of Cypher, I can use this query to get all nodes with relationships:

MATCH (n)-[r]-(m) RETURN n,r,m

However, I'm missing nodes without any relationships.

In trying to query the missing nodes, this attempt gives me the error: Variable 'r' not defined

MATCH (n) WHERE NOT (n)-[r]->() RETURN n

And, this attempt shows zero results:

MATCH (n)-[r]->() WHERE r is null RETURN n

I can see the stragglers with:

MATCH (n) RETURN n

But, then I'm missing the relationships.

How do I phrase my query to find all nodes and all relationships without duplicates?

Upvotes: 0

Views: 203

Answers (1)

stdob--
stdob--

Reputation: 29172

You can try the OPTIONAL MATCH:

MATCH (n)
OPTIONAL MATCH (n)-[r]-(m)
RETURN n, r, m

Upvotes: 1

Related Questions