Cartesian (Cross) Joins in SQL.

Kasim Ali
1 min readNov 15, 2022

--

In this medium post, we will learn about Cartesian Joins in SQL.

Learning Objectives:

  • Define Cartesian joins.
  • Describe some cases where Cartesian joins might be helpful.
  • Write appropriate SQL to establish a Cartesian join.
Cartesian (Cross) Joins in SQL | OnyxWrench

One important thing to consider is that Cartesian joins are computationally expensive. If you have two tables with 10 rows each, you will run 100 queries to achieve a cartesian join.

Cartesian (Cross) Join Example.

Here is an example.

SELECT product_name,
unit_price,
company_name
FROM suppliers CROSS JOIN products

Notice that table 1 is called suppliers and table 2 is called products.

Let's say that table 1 has 23 records and table 2 has 33 records. This means that there will be 759 rows once the query has finished executing.

There is also no guarantee that the columns you want will match any particular value.

This is why this particular join is rarely used and why caution is advised.

I would also love to connect on Twitter, LinkedIn or on my Website. I am not sure what value I could provide you with but if you reach out, I would be more than happy to have a conversation or talk about what I have written here.

--

--

No responses yet