Query most number of friends

22 views
Skip to first unread message

Jason

unread,
Sep 25, 2015, 1:36:35 AM9/25/15
to Neo4j
Person has some friends.

How do we list the name of the Person node with the most number of friends? 


Thanks

Michael Hunger

unread,
Sep 25, 2015, 2:27:01 AM9/25/15
to ne...@googlegroups.com
this is a very common query listed everywhere in the docs and training material.

match (p:Person)-[:FRIEND_OF]->()
return p, count(*) as c
order by c desc limit 10

faster:

match (p:Person)
return p, size( (p)-[:FRIEND_OF]->() ) as c
order by c desc limit 10

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason

unread,
Sep 25, 2015, 11:58:12 AM9/25/15
to Neo4j
Hi Michael,

Thanks.

You answer return will like this 
A    6
B    5
C    4

But I want this
A    6
B    6


Any revision? Thanks

Clark Richey

unread,
Sep 25, 2015, 12:10:24 PM9/25/15
to ne...@googlegroups.com
I just noticed you use of a size function here. Is that a recent addition? I can’t find documentation on that. Thanks!


Clark Richey


Benoit Simard

unread,
Sep 30, 2015, 9:22:02 AM9/30/15
to ne...@googlegroups.com
Hi,

@Jason : I don't understand what you want exactly, and specially why B haven't the same
result on your queries ...

@Clark :

You can find documentation on snapshot (so for 2.3-SNAPSHOT) cypher refcard : http://neo4j.com/docs/snapshot/cypher-refcard/ (@see patterns section)

I can tell you that this works on a 2.1.8 version. But, I can't tell you when this was adding to cypher.

Cheers.
Reply all
Reply to author
Forward
0 new messages