Data Model along with Count's is as follows:
Relationship: AA(self-relation with nodes of label A) count: 36, AB(from A to B) count:0
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
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,
If I am interpreting your explanation correctly, the results of query1 shows there are no nodes B connected to nodes A, for nodes A that have a self relationship. If this is correct, the match statement in query2 would produce no records for all nodes A that have a self-relationship. The other option is nodes B related to nodes A, for those nodes A that do not have a self-relationship. There must not be any of those as well.