Stav Alfi
Stav Alfi

Reputation: 13923

Neo4j - Match by multiple relationship types

I want to match between entities by multiple relationship types.

Is it possible to say the following query:

match (Yoav:Person{name:"Yoav"})-[:liked & watched & ... ]->(movie:Movie) return movie

I need "and" between all the relation types; Yova liked and watched and .. a movie.

Upvotes: 38

Views: 24370

Answers (1)

Bruno Peres
Bruno Peres

Reputation: 16355

Yes, you can do something like:

match (gal:Person{name:"Yoav"})-[:liked|:watched|:other]->(movie:Movie) 
return movie

Take a look in the docs: Match on multiple relationship types

EDIT:

From the comments:

I need "and" between the relation types.. you gave me an "or"

In this case, you can do:

match (Yoav:Person{name:"Yoav"})-[:liked]->(movie:Movie),
(Yoav)-[:watched]->(movie),
(Yoav)-[:other]->(movie)
return movie

Upvotes: 61

Related Questions