Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cyhper combine two columns into a single

Tags:

neo4j

cypher

I couldn't find a similar post, so if you already know one or if my question is not the proper one, please let me know.

I have this query

MATCH
  (t:Taxi {name:'Taxi1813'})<-[:ASSIGNED]-(u2:User)-[rd2:DROP_OFF]->
  (g2:Grid)-[r:TO*1..2]-(g:Grid)<-[rd:DROP_OFF]-(u:User)-[:ASSIGNED]->(t)
WHERE ID(u2) < ID(u) AND rd2.time >= '04:38' AND rd2.time <= '04:42'
WITH DISTINCT u2, g2, u, g, rd2, rd
MATCH p=shortestPath((g2)-[r:TO*1..2]-(g))
WITH rd2, rd,u2, g2, u, g, p, REDUCE(totalTime = 0, x IN RELATIONSHIPS(p) | totalTime + x.time) AS totalTime
WHERE totalTime <= 4
RETURN u2.name, u.name

So at the end i got two columns

u2.name  u.name
User179  UserTest
User177  User179

Is there is a way or function to merge both columns into a single one and remove duplicates

Users
User179
User177
UserTest

Any suggestions? Thank you

like image 298
marhg Avatar asked Jan 07 '16 15:01

marhg


1 Answers

You can combine the two collections into a single collection and then return just the distinct items.

WITH ['User179', 'User177'] AS list1
, ['UserTest', 'User179'] AS list2
UNWIND list1 + list2 AS item
RETURN DISTINCT item

Alternatively, if you are using APOC you could use apoc.coll.union() instead.

WITH ['User179', 'User177'] AS list1
, ['UserTest', 'User179'] AS list2
RETURN apoc.coll.union(list1,list2)
like image 155
Dave Bennett Avatar answered Nov 15 '22 07:11

Dave Bennett