Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-09-2019 05:27 PM
Hi,
I have :Person, :Question, and :Answer nodes. A person can either answer a question or skip it. If they answer the question, I'm adding a relationship (:ANSWERED) between the :Person node and the :Answer node. If they decide to skip it, I'm adding a relationship (:SKIPPED) between the :Person node and the :Question node. I need to find a :Question that hasn't been answered or skipped to present to the user. Right now, I'm just trying to find the ones that haven't been skipped. This is my query:
MATCH (p:Person {firstName: 'Leeland'})-[r]->(q:Question)
WHERE r IS NULL
RETURN q
I found some SO answers that claim this should work...but they're from version 2.2 (so...a bit old). I also tried using it with an OPTIONAL match...that didn't work either. It returned null.
MATCH (p:Person {firstName: 'Leeland'})
OPTIONAL MATCH (p)-[r]->(q:Question)
WHERE r IS NULL
RETURN q
I have the :Person node and two :Question nodes created. I also put a :SKIPPED relationship between the :Person and :Question node.
Any thoughts on what I'm doing wrong?
Solved! Go to Solution.
05-09-2019 05:53 PM
OK...I feel silly now. I stared at this problem for almost 3 hours before I posted the question. I went to dinner, came back and posted the question and found the answers myself. The following query is providing the results I need.
MATCH (q:Question)
WHERE NOT (q)-[*]-(:Person {firstName: 'Leeland'})
RETURN DISTINCT q
Thanks for reading 🙂
05-09-2019 05:34 PM
Update. I found another post that showed another way of writing the query and I tried it. This shows the non-skipped question. Now to work on filtering out the answered ones...
MATCH (q:Question)
WHERE NOT (q)-[:SKIPPED]-(:Person {firstName: 'Leeland'})
RETURN DISTINCT q
05-09-2019 05:53 PM
OK...I feel silly now. I stared at this problem for almost 3 hours before I posted the question. I went to dinner, came back and posted the question and found the answers myself. The following query is providing the results I need.
MATCH (q:Question)
WHERE NOT (q)-[*]-(:Person {firstName: 'Leeland'})
RETURN DISTINCT q
Thanks for reading 🙂
All the sessions of the conference are now available online