cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Question about cypher query counting results

hi
i am using neo4j desktop for mac version 1.1.1.2
with neo browser 3.2.13
i have a simple graph with USERS and PAGES and relationship called LIKES
USERS likes different pages
so there are different USERS liking same PAGES.

i would love to make a query with cypher to show me only the PAGES liked by more than x USERS.
and i did it with this:

MATCH ()-[r:LIKES]->(n)
WITH n, count(r) as conto
WHERE conto > 5
RETURN n;

the problem is that like this i can only see pages.
what if i want to see pages and users and relationships?

thank you for the support

2 REPLIES 2

A better approach is to use the size() function on the pattern, which will use the degree of the relationship type for each node instead of actually expanding/traversing the relationships.

Once you use this to filter to the pages in question (and you should be using labels for your query), then you can actually do the work of expanding out and returning the interested paths for display. Assuming your labels are User and Page:

MATCH (n:Page)
WHERE size(()-[:LIKES]->(n)) > 5
MATCH p = ()-[:LIKES]->(n) 
RETURN p;

thank you
that was really helpful