keithpjolley
keithpjolley

Reputation: 2263

Neo4j Cypher query - relationship with an "or"

I'm trying to get a named relationship with an or in the query. I'm thinking the query should look similar to:

MATCH (A:person)-[B (:ACTED_IN|:DIRECTED)]->(C:person) RETURN A, B, C

but no matter how I put in the parens I get an error. I suppose a UNION would do the trick but was hoping that there was some way of doing it similar to the above. TIA.

EDIT: This does what I want but seems not the way to do it.

MATCH (A:person)-[B]->(C:person) WHERE type(B)="ACTED_IN" OR type(B)="DIRECTED" RETURN A,B,C

Upvotes: 1

Views: 1944

Answers (1)

Mrinal Roy
Mrinal Roy

Reputation: 979

I am a new user so I do not have the option to comment on questions yet. I am guessing you are trying to get the person who either acted in or directed the movie. Its described in official Cypher Documentation: Match on multiple relationship types.

With Demo Movie Data on Neo4j to get persons from The Matrix movie, I would use this:

MATCH (TheMatrix { title: 'The Matrix' })<-[rel:ACTED_IN|:DIRECTED]-(person)         
RETURN person.name, rel

Upvotes: 8

Related Questions