Suppose we are interested all the persons who have income of greater and 185000 and not live in Capitola.
Copy
MATCH (resident:person WHERE resident.income > 185000)OPTIONAL MATCH (resident)-[:lives_is]->(c:city) WHERE c.name <> 'Capitola' RETURN p.name as Person, c.name as City
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.OutputThe optional match ensures that people without city connections are still returned