EdMkn
EdMkn

Reputation: 13

How to use the result of another query?

I was making some requests on Neo4j, and I've a little trouble at making one in particular.

These are the nodes and relationships I have on my database enter image description here

Two of the elements:

enter image description here

enter image description here

I want to return the persons who are driving ("conduire") the same "Voiture" as Alice. This is what I wrote:

MATCH ((a:Personne)-[p:Conduire]->(b:Vehicule))
WHERE  b.`Type`='Voiture' AND id(b) in [MATCH ((a:Personne)-[p:Conduire]->(b:Vehicule))
WHERE  a.Nom='Alice' 
RETURN id(b)]
RETURN a.Nom

Upvotes: 1

Views: 225

Answers (1)

jose_bacoy
jose_bacoy

Reputation: 12684

Here is the query to return the persons who are driving the same car as Alice. Note that this will not return Alice because the match on b will not repeat the match made on a.

MATCH (a:Personne)-[:Conduire]->(:Vehicule)<-[:Conduire]-(b:Personne)
WHERE  a.Nom='Alice' 
RETURN b.Nom

Upvotes: 1

Related Questions