Re: How to join two query results into a single one?

Showing 1-5 of 5 messages
Re: How to join two query results into a single one? Florian B. 1/22/13 6:21 AM
I think you can work with optional relationship here:

START me = node(1) MATCH me-[:KNOWS*0..1]-friend-[:UPDATES_STATUS]-> statusUpdate RETURN statusUpdate


Regards,
Florian


On Tuesday, January 22, 2013 3:03:26 PM UTC+1, Sarpdoruk Tahmaz wrote:

Assume that my project is Facebook. I want to display a feed which consists of my status updates and my friends' status updates both.

Here are the relations;

  • user KNOWS user
  • user UPDATES_STATUS status

This is how I get my friends status updates;

START me = node(1) MATCH me-[:KNOWS]-()-[:UPDATES_STATUS]->friendsStatusUpdates RETURN friendsStatusUpdates

And this is how I get my own status updates;

START me = node(1) MATCH me-[:UPDATES_STATUS]->myStatusUpdates RETURN myStatusUpdates

Both queries work fine but I need a single query that combines these two.

Here is the StackOverflow link for the same question.


Thanks in advance.

unk...@googlegroups.com 1/22/13 6:47 AM <This message has been deleted.>
Re: How to join two query results into a single one? Sarpdoruk Tahmaz 1/22/13 1:57 PM
I did not realize that this query gives duplicates, it works well but provides duplicates in return.  I guess, firstly it finds 0 level deep nodes then it traverses whole graph one more to find at most 1 level deep nodes.  Here is the problem; at most 1 level deep means it includes 0 level deep nodes too so at the end there are 2 sets of 0 level deep nodes.  I added DISTINCT to get rid of duplicates and it worked just fine, but if there are any other solution to duplicates without using duplicated I'd appreciate that too.

START me = node(1) MATCH me-[:KNOWS*0..1]-friend-[:UPDATES_STATUS]-> statusUpdate RETURN DISTINCT statusUpdate


Thanks.
Re: How to join two query results into a single one? Florian B. 1/23/13 12:25 AM
Mh what you can do is separate you query in two parts. First part get all nodes you want to check the status of, me and my friends. In the second part you get the status updates.

START me = node(1)
MATCH
me-[:KNOWS*0..1]-friend
WITH distinct friend
MATCH
friend-[:UPDATES_STATUS]-> statusUpdate
RETURN DISTINCT
statusUpdate

With the WITH statement you define which variables of the previous part should be used in the next part.  
Re: How to join two query results into a single one? Sarpdoruk Tahmaz 1/23/13 2:25 AM
That worked just fine.  Thanks for the alterative solution using WITH statement.