Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 291
Peni Avatar asked Sep 20 '17 12:09

Peni


People also ask

What is Cartesian product in relational algebra?

In relational algebra, the Cartesian product of two relations R1 and R2 represents all of the possible combinations of R1 tuples and R2 tuples.

What is Cartesian product example?

In mathematics, the Cartesian Product of sets A and B is defined as the set of all ordered pairs (x, y) such that x belongs to A and y belongs to B. For example, if A = {1, 2} and B = {3, 4, 5}, then the Cartesian Product of A and B is {(1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5)}.

What is the Cartesian product of two relations?

The Cartesian product of two sets A and B, denoted A × B, is the set of all ordered pairs where a is in A and b is in B. A×B = {(a, b): a ∈ A and b ∈ B}.

What is Cartesian product and set difference in DBMS?

Set Difference (-) is used to retrieve the tuples which are present in R but not in S(R-S). Cartesian product (X) is used to combine each tuple from first relation with each tuple from second relation. Rename (ρ) is used to rename the output relation.


1 Answers

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

like image 191
Victor Medeiros Avatar answered Sep 21 '22 05:09

Victor Medeiros