0
votes

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?

1

1 Answers

2
votes

You can try the OPTIONAL MATCH:

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