OPTIONAL MATCH
Left-join semantics -- include nodes even when the pattern doesn't match. Unmatched variables return null instead of filtering the row out.
Syntax#
MATCH (a:Label) OPTIONAL MATCH (a)-[r:TYPE]->(b) RETURN a, bExample#
MATCH (p:Person)
OPTIONAL MATCH (p)-[:WORKS_AT]->(c:Company)
RETURN p.name, c.nameIf a person has no WORKS_AT relationship, c.name returns null instead
of omitting the person from results.
See Also#
- MATCH — required matching
- IS NULL / IS NOT NULL — null predicates
Try it
Open ↗⌘↵ to run
Loading engine…