Is Cartesian Product same as Full Outer Join found in Relational Database SQL? I ask because I am taking a Discrete Mathematics course and I just want a better understanding of how what I am studying (Cartesian Product) applies to or maps to what I do when developing software (SQL Joins).
1 Answer
No: the Cartesian product is not the same as SQL FULL OUTER JOIN
.
For example: if A = {1,2} and B = ∅, then A × B = {1,2} × ∅ = ∅, i.e. the Cartesian product yield the empty set. But, since FULL OUTER JOIN
does not require each record in the two joined tables to have a matching record, if B is empty and A is not, FULL OUTER JOIN
will still return some rows.
However, CROSS JOIN
will return the Cartesian product of rows from tables in the join.
The link between is SQL and discrete mathematics is relational algebra (cf. Codd's theorem) if you want to check out more the maths behind SQL.
-
2
-
$\begingroup$ No, cross join is called "relational Cartesian product" but it it isn't Cartesian product. The output of cross join contains tuple union/join/concatenations of elements of input sets. Cartesian product of n sets returns n-tuples, which here would be 2-tuples where each element is an input tuple. Cross join returns a certain subset of the Cartesian product of certain projections of input tables. $\endgroup$– philipxyMay 8, 2020 at 16:27