Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Cartesian product and cross join?

Tags:

sql-server

I am working on SQL Server 2008, and wanted to know about what is the differnce between Cartesian Product and Cross Join. Can somebody please help me to clear the concept?

like image 523
Vikrant More Avatar asked Aug 08 '12 09:08

Vikrant More


People also ask

Is Cartesian product and join same?

In SQL Server, the cartesian product is really a cross-join which returns all the rows in all the tables listed in a query: each row in the first table is paired with all the rows in the second table.

What is the difference between Cartesian product and cross product?

It's just the same symbol, and definitely not the same thing: the Cartesian product is a set (of vectors), the cross product is a vector.

What is the difference between Cartesian product and natural join?

The cross join produces the cross product or Cartesian product of two tables whereas the natural join is based on all the columns having the same name and data types in both the tables.

What is the difference between Cartesian product and full outer join?

CROSS JOIN is simply Cartesian Product of two tables, irrespective of any filter criteria or any condition. FULL OUTER JOIN gives unique result set of LEFT OUTER JOIN and RIGHT OUTER JOIN of two tables. It also needs ON clause to map two columns of tables.


3 Answers

When you do Cross join you will get cartesian product. Each row in the first table is matched with every row in the second table

enter image description here

like image 195
Joe G Joseph Avatar answered Oct 05 '22 16:10

Joe G Joseph


CROSS JOIN

This join is a Cartesian join that does not necessitate any condition to join. The resultset contains records that are multiplication of record number from both the tables.

cross join

/* CROSS JOIN */
SELECT t1.*,t2.*
FROM Table1 t1
CROSS JOIN Table2 t2

Sorce:
APRIL 13, 2009 BY PINAL DAVE
SQL SERVER – Introduction to JOINs – Basic of JOINs

like image 20
Michel Ayres Avatar answered Oct 05 '22 16:10

Michel Ayres


Both the joins give same result. Cross-join is SQL 99 join and Cartesian product is Oracle Proprietary join.

A cross-join that does not have a 'where' clause gives the Cartesian product. Cartesian product result-set contains the number of rows in the first table, multiplied by the number of rows in second table. (Resulting in a higher dimension in the resulting set).

like image 38
NG. Avatar answered Oct 05 '22 15:10

NG.