简体   繁体   中英

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?

You can try the OPTIONAL MATCH :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM