Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-08-2022 06:28 AM
I have created a vehicle make called `Toyota` and also created a new node store my vehicle models.
CREATE (Make:make{name: "Toyota"})
CREATE (Model:model {name: "Camry"})
CREATE (Make)-[r:MODEL_OF]->(Model)
RETURN Make, Model
I added two more vehicle models
CREATE (Model:model {name: "Vitz"})
CREATE (Model:model {name: "Corolla"})
and linked the two models to `Toyota`
MATCH (a:make), (b:model) WHERE a.name = "Toyota" AND b.name = "Vitz"
CREATE (a)-[r: MODEL_OF]->(b)
RETURN a,b
MATCH (a:make), (b:model) WHERE a.name = "Toyota" AND b.name = "Corolla"
CREATE (a)-[r: MODEL_OF]->(b)
RETURN a,b
How can i return all models of make `Toyota` that have the relationship `MODEL_OF`?
Solved! Go to Solution.
10-08-2022 08:42 AM
Try this:
match(n:make{name:"Toyota"})-[:MODEL_OF]->(m:model)
return m.name as model
Just a note, I would have the relationship in your model directed the opposite way, i.e. a model is-a model of a make.
10-08-2022 08:42 AM
Try this:
match(n:make{name:"Toyota"})-[:MODEL_OF]->(m:model)
return m.name as model
Just a note, I would have the relationship in your model directed the opposite way, i.e. a model is-a model of a make.
10-08-2022 09:16 AM
I have reversed the relationships
CREATE (Make:make{name: "Toyota"})
CREATE (Model:model {name: "Camry"})
CREATE (Model:model {name: "Vitz"})
CREATE (Model:model {name: "Corolla"})
Relationships
MATCH (a:model), (b:make) WHERE a.name = "Vitz" AND b.name = "Toyota"
CREATE (a)-[r: MODEL_OF]->(b)
RETURN a,b
MATCH (a:model), (b:make) WHERE a.name = "Corolla" AND b.name = "Toyota"
CREATE (a)-[r: MODEL_OF]->(b)
RETURN a,b
MATCH (a:model), (b:make) WHERE a.name = "Camry" AND b.name = "Toyota"
CREATE (a)-[r: MODEL_OF]->(b)
RETURN a,b
How can i modify your query?
10-08-2022 09:20 AM
Solved it like this
MATCH (Make:make {name: "Toyota"})<-[r:MODEL_OF]-(n)
RETURN n.name as Model
All the sessions of the conference are now available online