Christophe Ramet
Christophe Ramet

Reputation: 666

Cartesian Product in Relational Algebra

I'm a total begginer in Relational Algebra and I don't manage to fully understand how cartesian product works.

I want to know what happen in cartesian product when my two table have common attributes. I have no problem to understand when both table don't have any attribute in common.

For instance I tried to understand on example I made myself.

T1                          T2
----------                  -----------
A   B   C                   A    B   D
1   4   7                   1    4   8
2   5   3                   2    9   5
4   7   1                   7    3   2

If I want to do T1 x T2, when I want to write the line that is the concatenation of the first line of T1 A=1 , B=4 , C=7 and the second line of T2 A=2 ,B=9 ,C=5 , what happen to the column A and B ?

If you could show me the result of T1 x T2 it would be really useful!

Upvotes: 6

Views: 6212

Answers (1)

Victor Medeiros
Victor Medeiros

Reputation: 116

Edit: As discussed on comment section. I'm editing this answer for a proper understanding of the question.

As this is a possible duplicate, refer to this link: Cartesian products of tables that contains same columns

First, it depends on the algebra that you are using. For some, the cartesian product can be done between tables with common attributes, similar to a cross join, and on other algebras the cartesian product is not permitted, so you would have to rename the attributes.

p.s: Look up Cross Joins as they are similar to a cartesian product but with no conditions to join, see expected result of a cross join of your example tables:

    T1                      T2                T1 X T2
----------              -----------     =    ----------------------------
A   B   C                A    B   D          T1.A T1.B T1.C T2.A T2.B T2.D
1   4   7                1    4   8           1     4   7    1    4    8
2   5   3                2    9   5           1     4   7    2    9    5
4   7   1                7    3   2           1     4   7    7    3    2
                                              2     5   3    1    4    8
                                              2     5   3    2    9    5
                                              2     5   3    7    3    2
                                              4     7   1    1    4    8
                                              4     7   1    2    9    5
                                              4     7   1    7    3    2 

refer link: What is the difference between Cartesian product and cross join?

Also, i highly recommend you to check this out and try it yourself!

RelaX - relational algebra calculator http://dbis-uibk.github.io/relax/index.htm

Upvotes: 7

Related Questions