Querying
OPTIONAL MATCH
Use OPTIONAL MATCH to find patterns that might not exist, returning empty values when patterns don’t match. The OPTIONAL MATCH clause works like MATCH but allows parts of the pattern to be missing. It preserves nulls in the result when the pattern does not fully match, similar to a left outer join in
relational databases.
This query finds all Person nodes where the income is greater than 185000, and optionally matches cities they’re connected to (excluding Capitola). If a person isn’t connected to any city, the City column returns empty, but the person is still included in the results.
Output
The optional match ensures that people without city connections are still returned