How can I subtract the same returned values with different conditions in Neo4j in a single statement How can I subtract the same returned values with different conditions in Neo4j in a single statement database database

How can I subtract the same returned values with different conditions in Neo4j in a single statement


If you put each in a collection and then filter out the ones in one collection that aren't in the other you will effectively minus one from the other.

// put the result of the first set in a collectionMATCH (n)-[:someRelation]->(m) WHERE n.name='firstN' WITH collect(m.cal) as m_cal_coll_1//// put the second set in a collectionMATCH (n)-[:someRelation]->(m) WHERE n.name='Second'WITH m_cal_coll_1, collect(m.cal) as m_cal_coll_2//// return items in the first that are not in the secondreturn filter(x IN m_cal_coll_1 WHERE not x in m_cal_coll_2 )