Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I combine multiple rows in neo4j?

Tags:

neo4j

cypher

I have the following nodes:

p:Person
s:Skill

And the relationship is: (p)-[KNOWS]-(s).

My query is:

MATCH (p:Person)-[r:KNOWS]->(s:Skill) 
WHERE p.Name=~'Julie.*' 
RETURN (p.Name),(s.Name)

The Output is:

╒════════════╤══════════════════════════════╕
│(p.Name)    │(s.Name)                      │
╞════════════╪══════════════════════════════╡
│Julie Rocha │Knowledge Management          |
├────────────┼──────────────────────────────┤
│Julie Rocha │MongoDB                       │
└────────────┴──────────────────────────────┘

The Desired Output is:

╒════════════╤══════════════════════════════╕
│(p.Name)    │(s.Name)                      │
╞════════════╪══════════════════════════════╡
│Julie Rocha │Knowledge Management, MongoDB |
└────────────┴──────────────────────────────┘

How can I accomplish this? Any help is appreciated!

like image 336
Arjun Avatar asked Oct 26 '25 09:10

Arjun


1 Answers

Use collect():

MATCH (p:Person)-[r:KNOWS]->(s:Skill) 
WHERE p.Name =~ 'Julie.*' 
RETURN p.Name, collect(s.Name) AS skill

In the result, the skill attribute will be a list.

like image 182
Gabor Szarnyas Avatar answered Oct 29 '25 06:10

Gabor Szarnyas