Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-13-2020 08:17 PM
Query 1:
Match (n:Product) where n.brand = 'Apple' return n
Query 2:
Match (n:Product) -[r:hasBrand]->(m:Brand {name:'Apple'}) return n
Is possible merge these two into 1?
05-14-2020 01:10 AM
By merge do you merge do you mean where Product.brand = Apple and Brand.name = Apple?
If not then please lete us know the meaning of merge
05-14-2020 10:52 AM
Yes. My Product has a 'brand' property, and also it has a 'hasBrand' relationship to Brand, which isn't good design. I want to find all products which has a brand associated, which could be through either the property n.brand, or the relationship [:hasBrand], and that's why I wrote 2 separate queries to get two sets of results, and then combine together.
My question, how to write this as one query to achieve the same effect?
05-14-2020 11:57 AM
Are you saying you have set of Product which are associated with any Brand
and both are disjoint sets?
05-14-2020 12:44 PM
This should do the trick:
MATCH (n:Product { brand = 'Apple' })
OPTIONAL MATCH (n) -[r:hasBrand]-> ( m:Brand {name:'Apple'})
return n
05-15-2020 09:57 AM
That's great and thank you!
05-15-2020 10:01 AM
@sebastian A similar question:
How to query 'products which has the 'brand' property but doesn't have a hasBrand relationship'?
05-15-2020 11:59 PM
... WHERE r IS NULL ?!
05-16-2020 03:08 AM
What exactly are you trying to do there ?
Are you trying to just find the brand Apple ?
Anyways you can combine both by using OPTIONAL MATCH attached to the 2nd query.
All the best
All the sessions of the conference are now available online