cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Difference between Cypher queries

Hello everyone.
I want to output the difference between two Cypher queries, or find an equivalent workaround to achieve that.

I have these query:

MATCH (Role:XmlTag)-[:IS_CHILD_OF]->(RoleSequence:XmlTag)-[:IS_CHILD_OF]->(RoleSequences:XmlTag)-[:IS_CHILD_OF]->(exclusive:XmlTag)
WHERE exclusive._name="orm_ExclusionConstraint" AND exclusive.Name CONTAINS "ExclusiveOr"
return distinct exclusive.id AS ID, exclusive.Name AS name, Role.ref AS roleId
MATCH (Role:XmlTag)-[:IS_CHILD_OF]->(RoleSequence:XmlTag)-[:IS_CHILD_OF]->(RoleSequences:XmlTag)-[:IS_CHILD_OF]->(exclusive:XmlTag)
WHERE exclusive._name="orm_ExclusionConstraint" AND exclusive.Name CONTAINS "ExclusiveOr"
MATCH (oial:XmlTag) WHERE oial._name="ormtooial_FactTypeMapsTowardsRole" AND oial.TowardsRole=Role.ref
MATCH (subtype:XmlTag)-[:IS_CHILD_OF]->(subtypeMetaRole:XmlTag)-[:IS_CHILD_OF]->(factRoles:XmlTag)-[:IS_CHILD_OF]->(subtypeFact:XmlTag) WHERE subtypeFact._name="orm_SubtypeFact" AND subtype._name="orm_RolePlayer" AND subtypeMetaRole._name="orm_SubtypeMetaRole" AND subtypeFact.id=oial.FactType
return distinct exclusive.id AS ID, exclusive.Name AS name, Role.ref AS roleId

The first query selects all the rows in the domain; the second one just a subset of the previous one.
I need the difference between the first and the second query.
I tried to merge the queries into a single one, but failed because there is no MINUS operator in Neo4j like in some SQL languages.
Could you please suggest a solution to this?
Thank you very much!

1 REPLY 1

ameyasoft
Graph Maven

If I understood correctly, second MATCH in your second query is filtering Role.ref and is taking only those with oial.TowardsRole=Role.ref. If you add Role.ref <> oial.TowardsRole in first query WHERE clause should give rest of the nodes (difference between first and second query). Here is the query:

MATCH (oial:XmlTag) WHERE oial._name="ormtooial_FactTypeMapsTowardsRole"
WITH oial

MATCH (Role:XmlTag)-[:IS_CHILD_OF]->(RoleSequence:XmlTag)-[:IS_CHILD_OF]->(RoleSequences:XmlTag)-[:IS_CHILD_OF]->(exclusive:XmlTag)
WHERE exclusive._name="orm_ExclusionConstraint" AND exclusive.Name CONTAINS "ExclusiveOr" AND Role.ref <> oial.TowardsRole
return distinct exclusive.id AS ID, exclusive.Name AS name, Role.ref AS roleId

Hope this works.