# Get Search nodes and their relationship with those nodes as well

**URL:** <https://community.neo4j.com/t/get-search-nodes-and-their-relationship-with-those-nodes-as-well/43251>\
**Category:** Cypher\
**Created:** [August 21, 2021, 7:01pm UTC](https://community.neo4j.com/t/get-search-nodes-and-their-relationship-with-those-nodes-as-well/43251 "2021-08-21T19:01:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skandagn](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/skandagn/32/7692_2.png) [@skandagn](https://community.neo4j.com/u/skandagn)\
**Post date:** [August 21, 2021, 7:01pm UTC](https://community.neo4j.com/t/get-search-nodes-and-their-relationship-with-those-nodes-as-well/43251/1 "2021-08-21T19:01:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dhruv.sharma8826](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dhruv.sharma8826/32/4888_2.png) [@dhruv.sharma8826](https://community.neo4j.com/u/dhruv.sharma8826)\
**Post date:** [August 22, 2021, 3:38am UTC](https://community.neo4j.com/t/get-search-nodes-and-their-relationship-with-those-nodes-as-well/43251/2 "2021-08-22T03:38:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![skandagn](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/skandagn/32/7692_2.png) [@skandagn](https://community.neo4j.com/u/skandagn)\
**Post date:** [August 23, 2021, 4:55pm UTC](https://community.neo4j.com/t/get-search-nodes-and-their-relationship-with-those-nodes-as-well/43251/3 "2021-08-23T16:55:34Z")

</div>

> [@dhruv.sharma8826](#):
>
> MATCH (n)-[r:FOLLOWING]-\>(m:USER{userid: 'RESULT\_USERID'}) RETURN m;

Perfect! Thanks for your quick inputs Dhurv.
