6
$\begingroup$

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

$\endgroup$

1 Answer 1

9
$\begingroup$

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.

$\endgroup$
2
  • 2
    $\begingroup$ Excellent. Thank you very much Frank. $\endgroup$
    – philologon
    Feb 8, 2014 at 22:26
  • $\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$
    – philipxy
    May 8, 2020 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.