# Search for all relationships of a node given the node id

**URL:** <https://community.neo4j.com/t/search-for-all-relationships-of-a-node-given-the-node-id/65003>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [November 17, 2023, 6:11pm UTC](https://community.neo4j.com/t/search-for-all-relationships-of-a-node-given-the-node-id/65003 "2023-11-17T18:11:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blurbee](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/blurbee/32/30078_2.png) [@blurbee](https://community.neo4j.com/u/blurbee)\
**Post date:** [November 17, 2023, 6:11pm UTC](https://community.neo4j.com/t/search-for-all-relationships-of-a-node-given-the-node-id/65003/1 "2023-11-17T18:11:31Z")

</div>

I'm using Neo4j 5.12 and using the Neo4j browser. The data is as shown below as an example.

`create (:PERSON {name:"John"})-[:MEMBER_OF]->(:CLUB {name:"BAB"})<-[:MEMBER_OF]-(:PERSON {name:"John"})`

I have two nodes in relationship with one. But I want to remove the duplicate. I wish to use the id to remove the duplicate element.

`match (p:PERSON)-[r]->() where elementId(p)=0 return r`

The above query does not match based on id.

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 17, 2023, 6:27pm UTC](https://community.neo4j.com/t/search-for-all-relationships-of-a-node-given-the-node-id/65003/2 "2023-11-17T18:27:44Z")

</div>

I think you are confusing id() and elementId(). the value zero looks like an id, not an elementId. elementIds look like the following:

4:51d44bb0-9c65-4d16-9cfa-b1bbba236953:30

---

<div class="post-metadata">

**Author:** ![dan.flavin1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dan.flavin1/32/749_2.png) [@dan.flavin1](https://community.neo4j.com/u/dan.flavin1)\
**Post date:** [November 20, 2023, 9:20pm UTC](https://community.neo4j.com/t/search-for-all-relationships-of-a-node-given-the-node-id/65003/3 "2023-11-20T21:20:59Z")

</div>

Under the assumption that you don't care which node with the `name:"John"` property and the associated ` [:MEMBER_OF]` relationship is removed, you can delete one of the nodes with:

```auto
MATCH (p1:PERSON {name:"John"})-[:MEMBER_OF]->(:CLUB {name:"BAB"})<-[:MEMBER_OF]-(p2:PERSON {name:"John"}) 
WHERE elementId(p1) < elementId(p2)
DETACH DELETE p1

```

The `DETACH DELETE` is needed because there can be no dangling relationships. Note that the create statement did precisely what you told it to do.
