# This tutorial should explain how to avoid Cartesian Products

**URL:** https://community.neo4j.com/t/this-tutorial-should-explain-how-to-avoid-cartesian-products/29612
**Category:** Feedback & Requests
**Created:** [November 25, 2020, 7:42pm UTC](https://community.neo4j.com/t/this-tutorial-should-explain-how-to-avoid-cartesian-products/29612 "2020-11-25T19:42:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![clem](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/clem/32/4364_2.png) [@clem](https://community.neo4j.com/u/clem)
#### Post date: [November 25, 2020, 7:42pm UTC](https://community.neo4j.com/t/this-tutorial-should-explain-how-to-avoid-cartesian-products/29612/1 "2020-11-25T19:42:46Z")

</div>

In this tutorial:

> **[Take the Cypher Fundamentals course with Neo4j GraphAcademy](https://graphacademy.neo4j.com/courses/cypher-fundamentals/?ref=redirect)**
>
> Learn Cypher in 1 hour

There is the query:

```auto
MATCH (a:Person), (m:Movie)
WHERE a.name = 'Michael Caine' AND m.title = 'Batman Begins'
CREATE (a)-[:ACTED_IN]->(m)
RETURN a, m

```

with an explanation that this query will create a cartesian product but it does NOT explain how to avoid that!

Avoiding a cartesian product is explained here:

> [@Avoid cartesian product when create relationships](https://community.neo4j.com/t/avoid-cartesian-product-when-create-relationships/13624):
>
> Hi! I'm new to neo4j and I try to find some help here. I have two sets of nodes say one is people and another is car.I want to create relationship between these two sets of nodes but I don't want to create relationships base on cartesian product of result return by match since it will take much time. The cypher statement I use like below: MATCH (a:test\_11),(b:test\_12) WHERE a.car ="0" AND b."price" = "1" MERGE (a)-[r:own{time:2020,location:"LA"}]-\>(b) Is there a way to write cyher which ca…

(I would have made a Pull Request on it, but I don't know where it lives in github.)

---

<div class="post-metadata">

### Author: ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)
#### Post date: [November 25, 2020, 11:53pm UTC](https://community.neo4j.com/t/this-tutorial-should-explain-how-to-avoid-cartesian-products/29612/2 "2020-11-25T23:53:06Z")

</div>

Yes that cypher statement does create a Cartesian join but it's a 1x1 Cartesian since each match returns only 1 row given the data model

---

<div class="post-metadata">

### Author: ![clem](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/clem/32/4364_2.png) [@clem](https://community.neo4j.com/u/clem)
#### Post date: [November 26, 2020, 12:03am UTC](https://community.neo4j.com/t/this-tutorial-should-explain-how-to-avoid-cartesian-products/29612/3 "2020-11-26T00:03:14Z")

</div>

That's not the point of my suggestion.

I got the warning but I didn't have any idea of how to fix it until today.

It's not immediately obvious how to **not** do a Cartesian Product.
