What is the difference between Cartesian product and cross join?
Asked Answered
P

7

26

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?

Portemonnaie answered 8/8, 2012 at 9:21 Comment(2)
You mean cartesian product? It is the same as cross join.Kerri
Have a look at the following article SQL SERVER – Introduction to JOINs – Basic of JOINs Specifically at the section CROSS JOINAlbaugh
P
41

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

Pardon answered 8/8, 2012 at 9:25 Comment(1)
I got it, CROSS JOIN = Cartesian product. Hope we achieve the same using, select * from table1, table2;Rhigolene
H
14

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

Headrick answered 23/5, 2014 at 19:56 Comment(0)
S
3

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).

Seraglio answered 8/8, 2012 at 10:50 Comment(0)
D
0

A cartesian join, also known as a cross join, is a type of join that produces the cartesian product of two relations. The cartesian product of two sets A and B is the set of all ordered pairs (a, b) where a belongs to A and b belongs to B. In most cases, cartesian joins are not very useful because they produce a large number of rows that are not relevant to the query. However, they can be useful in some cases, such as when you need to generate a list of all possible combinations of two sets.

Discernment answered 27/7, 2023 at 13:14 Comment(0)
M
0

Cross JOIN

SELECT *
FROM Table1 t1
CROSS JOIN Table2 t2

Cartesian Prouct

SELECT *
FROM Table1 t1, 
Table2 t2

They both have same result. i.e every row of table1 will be mapped with every row of table2 so total M*N number of rows will be there in final result

M=no. of rows in table 1

N=no. of rows in table 2

Merrile answered 6/2 at 12:30 Comment(0)
C
-1

Cartesian product does not have any condition and result set have total row as r=r1*r2 where r1 rows in first relation and r2 in second relation. joins satisfy specific conditions

Corn answered 15/10, 2021 at 7:26 Comment(0)
O
-1

when we do a cartesian product of two tables we don't need to find any kinda matched column. But in Join one column must have to be matched from both tables.

Ottoman answered 10/6, 2022 at 4:54 Comment(1)
What does this answer add to other answers already provided?Greenock

© 2022 - 2024 — McMap. All rights reserved.