I was trying to create a union of two optional matches (as shown below) but instead of a union I'm getting an intersection of the two. How should I change this query to get the required union?
optional match (a:PA)-[r2:network*2]-(b:PA) where a.last_name='smith'
And Not (a:PA)-[:network]-(b:PA)
optional match (a:PA)-[r3:network*3]-(b:PA) where a.last_name='smith'
And Not (a:PA)-[:network]-(b:PA)
return b.first_name, count(r2), count(r3)
This graph database is supposed to mimic a social network.Through the first optional match I have tried to locate second degree connections in the user's(smith's) network and the count of times they appear as a 2nd degree connection in his network. The second match does the same for the 3rd degree connections.
But the query is returning the intersection of the 2 optional matches instead of their union i.e I'm getting a count of only those names which can be mapped as both a 2 degree as well as a 3 degree connection with respect to the user(smith).
Instead I would like to get the name of all the 2nd degree and 3rd degree connections along with the counts. How shall I modify this query to get the required results?