In Cypher, nodes are queried if they have edges type A. How to display other edge type they have?

In my graph the edges have two types: A and B. I want to query all the nodes having edges type A. Within those nodes, if they have edges B then they should be displayed as well. So for example, if we have (node1)-[A]-(node2), (node3)-[A]-(node4), and if there are B edges between those 4 nodes, then only them should be displayed, not all other Bs.

I try both:

match (n)-[r:A]-(m) 
match (n)-[s:B]-(m) 
return n,r,s,m

and

match (n)-[r:A]-(m),
 (n)-[s:B]-(m) 
return n,r,s,m

But none of them works.

I don't use Neo4j Browser, so the edges need to be explicitly queried. The manual for MATCH doesn't help.


Try this, since you seem to be looking for triangles

MATCH (n)-[r1:A]-(m)-[r2:A]-(k)
OPTIONAL MATCH (k)-[r3:B]-(n)