Reputation: 1062
I have a db of drugs and manufacturers and I want to find all manufacturers who have produced multiple drugs. How can I get only the manufacturers and the drugs they have produced?
I'm currently using
match (a:Brand), (c:Manufacturer) where size((c)-[:PRODUCED]->()) >1 return a,c;
which returns manufacturers with more than one drug produced but also all drugs, regardless of manufacturer
Upvotes: 0
Views: 28
Reputation: 67044
This query uses the aggregating function, COLLECT
, to return a record for each manufacturer who makes multiple brands, along with a collection of those brands:
MATCH (m:Manufacturer)-[:PRODUCED]->(b:Brand)
WITH m, COLLECT(b) AS brands
WHERE SIZE(brands) > 1
RETURN m, brands;
Upvotes: 1
Reputation: 6026
Sounds like you only need to select the manufacturers, like so:
MATCH (c:Manufacturer) WHERE size((c)-[:PRODUCED]->()) > 1 RETURN c;
Upvotes: 0