Eadan Fahey
Eadan Fahey

Reputation: 373

Returning the node and related nodes of the node with the most relationships

In the Northwind Graph worked example provided by neo4j I can find the supplier with the most products with the query:

MATCH (s:Supplier)-[r]->(p:Product)
RETURN s, COUNT(r) as c
order by c DESC
limit 1

What I'm trying to do is return the supplier with the most products along with their products.

Upvotes: 1

Views: 87

Answers (1)

Martin Preusse
Martin Preusse

Reputation: 9369

You can simply add the Product to the RETURN statement:

MATCH (s:Supplier)-[r]->(p:Product)
RETURN s, COUNT(r) as c, collect(p)
order by c DESC
limit 1

Upvotes: 2

Related Questions