# Create relationship

**URL:** <https://community.neo4j.com/t/create-relationship/51266>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [January 31, 2022, 6:01pm UTC](https://community.neo4j.com/t/create-relationship/51266 "2022-01-31T18:01:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iganea9](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/iganea9/32/21194_2.png) [@iganea9](https://community.neo4j.com/u/iganea9)\
**Post date:** [January 31, 2022, 6:01pm UTC](https://community.neo4j.com/t/create-relationship/51266/1 "2022-01-31T18:01:31Z")

</div>

I'm defining the relationship between two entities, Variety and Treatment.  
match (s1:Variety),(c:Treatment)  
where id(s1)=0 and id(c)=4  
create (s1) - [rel:UNTREATED]-\> (c)  
return type(rel)  
Result is '(no changes, no records)'.  
In this context, an error occurs:  
_This query builds a cartesian product between disconnected patterns._

---

<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:** [January 31, 2022, 6:15pm UTC](https://community.neo4j.com/t/create-relationship/51266/2 "2022-01-31T18:15:23Z")

</div>

It worked for me. Are you sure the two nodes exist.

You can refactor the code as follows to eliminate the warning and to ensure the relationship doesn't get recreated every time you run the query:

match (s1:Variety) where id(s1)=0  
match (c:Treatment) where id(c)=1  
merge (s1) - [rel:UNTREATED]-\> (c)  
return type(rel)

Note: the id's are from my test data. Change appropriately.

---

<div class="post-metadata">

**Author:** ![iganea9](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/iganea9/32/21194_2.png) [@iganea9](https://community.neo4j.com/u/iganea9)\
**Post date:** [January 31, 2022, 6:20pm UTC](https://community.neo4j.com/t/create-relationship/51266/3 "2022-01-31T18:20:04Z")

</div>

> [@glilienfield](#):
>
> match (s1:Variety) where id(s1)=0  
> match (c:Treatment) where id(c)=1  
> merge (s1) - [rel:UNTREATED]-\> (c)  
> return type(rel)

Thanks. But the result is the same. The nodes exists.  
 ![11](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/3/1/31ccb30be34628a27efbaa8fcee44451c8491cbc.png)

Previously this was working. Current version Neo4j is 1.4.12.

---

<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:** [January 31, 2022, 7:18pm UTC](https://community.neo4j.com/t/create-relationship/51266/4 "2022-01-31T19:18:10Z")

</div>

You screenshot shows your label is "Varieties", not "Variety." There is also no label "Treatment." Could this explain it?

---

<div class="post-metadata">

**Author:** ![koji](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/koji/32/27564_2.png) [@koji](https://community.neo4j.com/u/koji)\
**Post date:** [February 1, 2022, 7:25pm UTC](https://community.neo4j.com/t/create-relationship/51266/5 "2022-02-01T19:25:59Z")

</div>

Hi @iganea9

Here is my environment.

```auto
macOS 12.2
Neo4j Desktop 1.4.12
Neo4j 4.4.3

```

I created the 5 nodes.

```auto
CREATE (:Variety); // id()=0
CREATE (:Label1); // id()=1
CREATE (:Label2); // id()=2
CREATE (:Label3); // id()=3
CREATE (:Treatment); // id()=4

```

Your Cypher works correctly.  
I ran it 3 times.

```auto
MATCH (s1:Variety),(c:Treatment)
  WHERE id(s1)=0 AND id(c)=4
CREATE (s1)-[rel:UNTREATED]->(c)
RETURN type(rel)

```

 ![スクリーンショット 2022-02-02 4.04.44](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/2/3/23fafb8b96d9fbcd0e40aa440631fa0bb4683e24.png)

 ![スクリーンショット 2022-02-02 4.06.48](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/0/a/0a47aa199046a6bd3e4a0b6d0e9e82eabc992c63.png)

You may be able to find the problem with this Cypher.

```auto
MATCH (n)
  WHERE id(n) IN [0,4]
RETURN n;

```
