Data Model along with Count's is as follows:
Nodes: A(40),B(100)
Relationship: AA(self-relation with nodes of label A) count: 36, AB(from A to B) count:0
Query1:
Match (p:A)-[b:AA]->(p1)
OPTIONAL MATCH (p1)-[d:AB]->(c:B)
RETURN p,p1,b,d,c
Output: A(40), AA(36), AB(0) and B(0). The output is the same as the expected output
Query2:
MATCH (p1:A)-[d:AB]->(c:B)
OPTIONAL Match (p)-[b:AA]->(p1)
RETURN p,p1,b,d,c
This query is prepared by rearranging the sequence in the first query.
Output By Neo4j: (no changes, no records)
Expected Output: A and AA data, as they are present in the graph even if the first sequence is not present.
Request you to go through the queries and suggest your thoughts, to return the data even if some patterns return no records.
Thanks & Regards,
Vinayak