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, b

Example#

MATCH (p:Person)
OPTIONAL MATCH (p)-[:WORKS_AT]->(c:Company)
RETURN p.name, c.name

If a person has no WORKS_AT relationship, c.name returns null instead of omitting the person from results.

See Also#

Try it
Open ↗
Loading engine…