+3 votes
in Databases by (71.8k points)
I want to find all movies an actor acted in, and for each film retrieved, find his/her costars in that movie. How to write Cypher for this query?

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

Here is the Cypher to find the list of movies Tom Hanks acted in, and for each film retrieved, it also finds Tom's co-actors

MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(films)<-[:ACTED_IN]-(coActors)
RETURN tom.name, films.title, coActors.name;

The above query will result like this:

╒═══════════╤════════════════════════╤════════════════════════╕
│"tom.name" │"films.title"           │"coActors.name"         │
╞═══════════╪════════════════════════╪════════════════════════╡
│"Tom Hanks"│"You've Got Mail"       │"Parker Posey"          │
├───────────┼────────────────────────┼────────────────────────┤
│"Tom Hanks"│"You've Got Mail"       │"Greg Kinnear"          │
├───────────┼────────────────────────┼────────────────────────┤
│"Tom Hanks"│"You've Got Mail"       │"Meg Ryan"              │
├───────────┼────────────────────────┼────────────────────────┤
│"Tom Hanks"│"You've Got Mail"       │"Steve Zahn"            │
├───────────┼────────────────────────┼────────────────────────┤
│"Tom Hanks"│"You've Got Mail"       │"Dave Chappelle"        │
├───────────┼────────────────────────┼────────────────────────┤
│"Tom Hanks"│"Apollo 13"             │"Ed Harris"             │
├───────────┼────────────────────────┼────────────────────────┤
│"Tom Hanks"│"Apollo 13"             │"Kevin Bacon"           │
├───────────┼────────────────────────┼────────────────────────┤
│"Tom Hanks"│"Apollo 13"             │"Gary Sinise"           │
├───────────┼────────────────────────┼────────────────────────┤
│"Tom Hanks"│"Apollo 13"             │"Bill Paxton"           │
├───────────┼────────────────────────┼────────────────────────┤

 

Related questions


...