Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-07-2020 05:09 PM
Hi there,
I have a requirement where i want to include multiple destination in my path.
My Original Graph
My requirement:
I want to find all the suppliers and the RISK associated with the Suppliers for a particular product.
match path =(p:Product{name:"Product2"}) <-[*..10] -(:Supplier)
return path
This query returns me all the suppliers for a particular product
match path =(p:Product{name:"Product2"}) <-[*..10] -(:Supplier)-[:AFFECTEDBY]-(:RISK)
return path
As you can see the 2 suppliers (name:"SupplierN+1") were not retrieved in the above graph.
So basically I need a combination of both the queries.
Can you please help me with the query to retrieve BOTH Suppliers (3 suppliers) and RISK associated with for a particular product.
Thanks Heaps
05-07-2020 08:10 PM
Try this:
match (p:Product{name:"Product2"}) <-[*..10] -(s:Supplier)
optional match (s)-[:AFFECTEDBY]-(r:RISK)
return p, s, r
05-07-2020 09:15 PM
thanks for your reply ameyasoft.
I tried the above query, but the problem is i lose the links along the path. screenshot below.
How can retain the path while getting BOTH Suppliers (3 suppliers) and RISK
05-08-2020 12:21 AM
Try this:
match (a:Supplier)-[]-(b:Supplier) where b.name <> a.name
with a, b
match path = (a)-[]-(b)-[*..10]->(p:Product)
where p.name = "Product2"
return path
05-09-2020 10:01 PM
This doesn't help. I am not sure if you got my question.
How can retain the path while getting BOTH Suppliers and RISK.
Is there a way i can put 2 destination nodes i.e. (destination:Supplier | :RISK)
match path =(p:Product{name:"Product2"}) <-[*..10] -(destination:Supplier | :RISK)
return path
05-10-2020 09:06 AM
match path = (a)-[]-(b:Supplier)-[*..10]->(p:Product)
where p.name = "Product2"
return path
05-12-2020 12:28 AM
Works , Thanks ameyasoft 🙂
05-10-2020 05:16 PM
Is there a way i can put 2 destination nodes i.e. (destination:Supplier | :RISK)
Yes.
MATCH path =(p:Product{name:"Product2"}) <-[*..10] -(destination)
WHERE destination:Supplier OR destination:RISK
RETURN path
If you don't mind working with multiple paths, then you can use this instead, which builds on the OPTIONAL MATCH approach suggested earlier:
MATCH path =(p:Product{name:"Product2"}) <-[*..10] -(s:Supplier)
OPTIONAL MATCH riskPath = (s)-[:AFFECTEDBY]-(:RISK)
RETURN path, riskPath
05-12-2020 12:32 AM
This is so helpful. Thanks a lot andrew 🙂
All the sessions of the conference are now available online