title: Cypher query for multiple relationships if either one is valid
body: <p>My graph is set up like this:</p>
  
  <pre><code>(:User)-[:LIVES_IN_COUNTRY]-&gt;(:Country)
  (:User)-[:LIVES_IN_STATE]-&gt;(:State)
  (:User)-[:LIVES_IN_CITY]-&gt;(:City)
  </code></pre>
  
  <p>I'm trying to build a dynamic cypher query to check all relationships but return results from only those that are valid</p>
  
  <p>For e.g if I only know Country name and state name, in that case I only pass valid names for country and state and "Not Available" for city. I have tried something like this:</p>
  
  <pre><code>Match(n:User)
  Match(n)-[:LIVES_IN_COUNTRY]-&gt;(:Country {name:'Canada'})
  Match(n)-[:LIVES_IN_STATE]-&gt;(:State {name:'Ontario'}) 
  Match(n)-[:LIVES_IN_CITY]-&gt;(:City {name:'Not Available'}) 
  </code></pre>
  
  <p>But, in this case, nothing is returned. How can I get users for Canada and Ontario in this case when City name is unavailable?</p>
  
  <p>Perhaps it is possible using seperate cypher queries but I was wondering if it possible to handle within one cypher query</p>
  
  <p>I have tried to use optional but it returns all users in all countries, states and so on. Not sure if it is possible with optional or something wrong in query</p>
  
  <pre><code>Match(n:User) 
  OPTIONAL Match (n)-[:LIVES_IN_COUNTRY]-&gt;(:Country{name:'Canada'}) 
  OPTIONAL Match (n)-[:LIVES_IN_STATE]-&gt;(:State {name:'Ontario'}) 
  OPTIONAL Match (n)-[:LIVES_IN_CITY]-&gt;(:City {name:'Not Available'}) 
  Return n.username,n.country, n.state, n.city
  </code></pre>