I'm new to Neo4j Community Edition 3.1.0 and I'm trying to create an efficient Cypher query that matches a relationship of a certain type (type A) between nodes ONLY if those nodes currently have a (type B) relationship between them. For instance, what I have right now is:
MATCH (n)-[:B]-(m)
WITH n,m
MATCH (n)-[r:A]-(m)
RETURN r
In my graph, there are significantly more (type B) relationships than (type A), so I'm worried that my query will be very inefficient since it is matching all the (type B) relationships first. Is my query correct; and if so, how can I make it more efficient?