cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Get Search nodes and their relationship with those nodes as well

skandagn
Node Link

I have a search query for a property which can be achieved by the following cypher query

MATCH (n: USER) WHERE n.fullname CONTAINS 'q' RETURN n

Say it matches 3 USER nodes and returns those 3

Then I want to see if there is a relationship with those nodes which is achieved by the following query which is handled by a for loop in python

MATCH (n: USER{userid: 'U1'})-[r:FOLLOWING]->(m:USER{userid: 'RESULT_USERID'}) RETURN m
(Executed 3 times for 3 results)

I want to do both of this in single query. How can it be achieved?

Thanks,
Skanda

2 REPLIES 2

Hi Skanda,

You can easily achieve this using 'WITH' to carry forward the result from the first query and use it into the second query.

Something like this-
MATCH (n: USER) WHERE n.fullname CONTAINS 'q'
WITH n
MATCH (n)-[r:FOLLOWING]->(m:USER{userid: 'RESULT_USERID'}) RETURN m;

This would show the same result as you expect under this one singe query.

skandagn
Node Link

Perfect! Thanks for your quick inputs Dhurv.