Join return lists in Cypher

3,594 views
Skip to first unread message

Deepak

unread,
Sep 24, 2012, 3:01:18 AM9/24/12
to ne...@googlegroups.com
Hi,

How do I join the return lists when I use with clause in Cypher SQL?

Eg.

Start n=node(1)
match n-[r]->m
with m.name? as Friends, 'Outgoing' as Type
match n<-[r]-m
with n.name?,m.name?,Friends, 'Incomoing' ....

Expected op:

Person A  - Person B - Outgoing
Person A  - Person C - Incoming

Is it possible to generate something like this?


Michael Hunger

unread,
Sep 24, 2012, 3:24:48 AM9/24/12
to ne...@googlegroups.com


Sent from mobile device

Am 24.09.2012 um 00:01 schrieb Deepak <shan...@gmail.com>:

Hi,

How do I join the return lists when I use with clause in Cypher SQL?

Eg.

Start n=node(1)
match n-[r]->m
with n,collect(m.name?) as Outgoing_Friends
match n<-[r]-m
Return n.name?,collect(m.name?) as incoming_Friends, Outgoing_Friends

Expected op:

Person A  - Person B - Outgoing
Person A  - Person C - Incoming

Is it possible to generate something like this?


--
 
 

Deepak

unread,
Sep 24, 2012, 4:37:15 AM9/24/12
to ne...@googlegroups.com
Michael,

The above query results the joining query result set in different column. Is it possible to union the result sets and put it under same column set like the sample out case in my previous post?

Thanks,
Deepak

Michael Hunger

unread,
Sep 24, 2012, 5:16:02 AM9/24/12
to ne...@googlegroups.com
with ...
return incoming_friends + outgoing_friends

Michael
> --
>
>

Andres Taylor

unread,
Sep 24, 2012, 5:41:11 AM9/24/12
to ne...@googlegroups.com
WITH is very different from UNION. SQL's UNION concatenates queries together, while WITH sends results from one query part, and uses it as context for the next query part.

We don't have UNION in Cypher. While you fake some parts of it using WITH-tricks, it's still not UNION.

Andrés

--
 
 



--
The best way to ask for Cypher help: http://console.neo4j.org/usage.html 

Deepak

unread,
Sep 25, 2012, 2:05:34 AM9/25/12
to ne...@googlegroups.com
Michael,

Still i get errors with the sql below -

Start n=node(13)
match n-[r]->m
with m.name? as outf
match n<-[r]-m
with m.name? as inf
return outf+inf

can you please help me over it?
Thanks,
Deepak 

Peter Neubauer

unread,
Sep 25, 2012, 2:32:12 AM9/25/12
to ne...@googlegroups.com
Deepak,
you need to use collect and pull over n, like

Start n=node(1)
match n-[r]->m
with collect(m.name?) as outf, n
match n<-[r]-m
with collect(m.name?) as inf, outf
return outf+inf

http://tinyurl.com/9tzmk9q

Cheers,

/peter neubauer

Neo4j 1.8.RC1 "Vindeln Vy" -
http://blog.neo4j.org/2012/09/neo4j-18rc1-really-careful-ftw.html

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Wanna learn something new? Come to @graphconnect.
> --
>
>

Deepak

unread,
Sep 25, 2012, 2:38:41 AM9/25/12
to ne...@googlegroups.com
Peter,
It works pretty fine. Thanks a lot..

-
Deepak
Reply all
Reply to author
Forward
0 new messages