# Relationship and Where conditions

(Rcfro2) #1

`MATCH (keanu:Person)-[:ACTED_IN]->()<-[:ACTED_IN]-(c), (c)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc)`

Without anything else, couldnt all the above indicated nodes be the same node? In other words, "keanu", "c"and "coc" could all refer to Keanu Reeves, for example. Is this correct?

Also, if we specified the following:

``````MATCH (keanu:Person)-[:ACTED_IN]->()<-[:ACTED_IN]-(c), (c)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc)
WHERE keanu <> c
``````

All we would be guaranteeing is that keanu and c are not equal, so therefore coc and keanu could be right? On that note, wouldnt the following also have a similar reasoning:

``````MATCH (keanu:Person)-[:ACTED_IN]->()<-[:ACTED_IN]-(c), (c)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc)
WHERE keanu <> coc
``````

Only keanu and coc are not equal, but keanu and c could be equal.

``````MATCH (keanu:Person)-[:ACTED_IN]->(movie:Movie),
(coActor:Person)-[:ACTED_IN]->(movie)
WHERE keanu.name = 'Keanu Reeves'
RETURN DISTINCT coActor.name;``````

(Stefan Armbruster) #2

It's important to understand one specific aspect of a path in Cypher: the very same relationship will never be used multiple times. Otherwise this would allow for infinite recursion.

That said, in your example `c` is never `keanu` - unless there are more than one `:ACTED_IN` relationships between the same actor and same movie.

(Rcfro2) #3

(Stefan Armbruster) #4

coactor and keanu can be the same if the movie nodes ( the ones referred to as `()` in your example are different.
Example:
Keanu coacted with Laurence Fishburne coacting in all 3 movies of the matrix trilogy

So a path would be:
`(keanu)-[:ACTED_IN]->(matrix)<-[:ACTED_IN]-(laurence)-[:ACTED_IN]->(matrix revolutions)<-[:ACTED_IN]-(keanu)`

q.e.d.

(Rcfro2) #5

I had several examples because I wanted to understand the logic in different contexts. No reason for the q.e.d. :) thanks.