cancel
Showing results for 
Search instead for 
Did you mean: 

Group NODES by CONTAINS

VilladsClaes
Node Clone
MATCH (l:WORD)<--(k:SENTENCE)
WITH l
MATCH (l)-[*]-(n:SENTENCE)
WHERE n.name CONTAINS l.name
WITH n.name AS NodeContainingTheWords, l.name AS TheWord
RETURN NodeContainingTheWords, TheWord

Returns the following

I want to group 1 and 2 so that I can ORDER BY which :SENTENCE CONTAINS the most WORDS

1 ACCEPTED SOLUTION

Cobra
Ninja
Ninja

Hello @VilladsClaes

You can aggregate by words or sentences with collect():

RETURN NodeContainingTheWords, collect(TheWord) AS words

Or

RETURN TheWord, collect(NodeContainingTheWords) AS sentences 

Regards,
Cobra

View solution in original post

1 REPLY 1

Cobra
Ninja
Ninja

Hello @VilladsClaes

You can aggregate by words or sentences with collect():

RETURN NodeContainingTheWords, collect(TheWord) AS words

Or

RETURN TheWord, collect(NodeContainingTheWords) AS sentences 

Regards,
Cobra

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.